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
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What does 3 mean in texting?
What are global variables?
Why cant I open a file by its explicit path?
Explain how can a program be made to print the line number where an error occurs?
explain what is a newline escape sequence?
Can we replace the struct function in tree syntax with a union?
write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);
What is masking?
What is the difference between null pointer and wild pointer?
What is the difference between new and malloc functions?
Can you please compare array with pointer?
Explain null pointer.
which type of aspect you want from the student.
What is the difference between exit() and _exit() function?