if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')
Answer Posted / haris
Try it. It will seriously work. You would appreciate it.
#include<stdio.h>
#include<conio.h>
int main()
{
int x;
int a;
int b;
int c;
int d;
int e;
int sum;
printf("Please enter a five digit number:\n");
scanf("%d",&x);
a=x%10;
b=(x/10)% 10;
c=(x/100)% 10;
d=(x/1000)%10;
e=(x/10000)%10;
sum=a+b+c+d+e;
printf("\n\nThe sum of all digits is %d.",sum);
getch();
return 0;
}
| Is This Answer Correct ? | 12 Yes | 5 No |
Post New Answer View All Answers
What is derived datatype in c?
What is the use of linkage in c language?
What are the advantages of c preprocessor?
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)
Explain what header files do I need in order to define the standard library functions I use?
What are the features of c languages?
What is array of structure in c?
What are the different types of control structures in programming?
Can the “if” function be used in comparing strings?
Can we change the value of #define in c?
What is f'n in math?
What are integer variable, floating-point variable and character variable?
pierrot's divisor program using c or c++ code
I heard that you have to include stdio.h before calling printf. Why?
What is the use of clrscr?