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 / joy
#include<stdio.h>
main ()
{
int num, a, b,c,d,e, sum;
printf ("Enter the five digit number : ");
scanf ("%d", &num);
e = num % 10;
d = (num / 10)% 10;
c = (num / 100)% 10;
b = (num / 1000)% 10;
a = (num / 10000)% 10;
sum= a+b+c+d+e;
printf ("The sum of the digits is: %d", sum);
}
| Is This Answer Correct ? | 25 Yes | 5 No |
Post New Answer View All Answers
What is the maximum length of an identifier?
What is the scope of an external variable in c?
What is a header file?
Explain the difference between the local variable and global variable in c?
How can I do serial ("comm") port I/O?
What is the difference between class and object in c?
What do header files do?
using for loop sum 2 number of any 4 digit number in c language
How do you use a pointer to a function?
Explain what are the standard predefined macros?
What is size of union in c?
What are # preprocessor operator in c?
What is keyword in c?
What is action and transformation in spark?
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above