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
How do you define CONSTANT in C?
How can I determine whether a machines byte order is big-endian or little-endian?
What is the difference between single charater constant and string constant?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
Does free set pointer to null?
formula to convert 2500mmh2o into m3/hr
What are the different types of control structures?
What is the right type to use for boolean values in c?
What is c value paradox explain?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
What is the advantage of a random access file?
What is a volatile keyword in c?
What are the functions to open and close the file in c language?
How can I prevent another program from modifying part of a file that I am modifying?
What is sizeof c?