0% found this document useful (0 votes)
2 views1 page

Basic Path Testing Day 2

The document contains two C programs. The first program counts the total number of digits in a given integer, while the second program calculates the sum of the digits of a given integer. Both programs prompt the user for input and display the results accordingly.

Uploaded by

Sadi Rifat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Basic Path Testing Day 2

The document contains two C programs. The first program counts the total number of digits in a given integer, while the second program calculates the sum of the digits of a given integer. Both programs prompt the user for input and display the results accordingly.

Uploaded by

Sadi Rifat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question 1:

#include <stdio.h>

int main() {
int num, count = 0;

printf("Enter a number: ");


scanf("%d", &num);

if (num == 0)
count = 1;
else {
while (num != 0) {
num = num / 10;
count++;
}
}

printf("Total digits = %d\n", count);


return 0;
}

Question 2:

#include <stdio.h>

int main() {
int num, sum = 0, digit;

printf("Enter a number: ");


scanf("%d", &num);

while (num > 0) {


digit = num % 10;
sum += digit;
num = num / 10;
}

printf("Sum of digits = %d\n", sum);

return 0;
}

You might also like