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 / thamizharasan
#include"stdio.h"
main ()
{
int number, last_digit, next_digit, total;
printf ("Enter the number whose sum of digits is to be calculated: ");
scanf ("%d", &number);
last_digit = number%10;
total = last_digit;
next_digit = (number/10) % 10;
total = total + next_digit;
next_digit = (number/100) % 10;
total = total + next_digit;
next_digit = (number/1000) %10;
total = total + next_digit;
next_digit = (number/10000) %10;
total = total + next_digit;
printf ("The sum of the digits of the entered number is: %d", total);
}
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
Why is c known as a mother language?
What are categories used for in c?
What are the types of bitwise operator?
When can you use a pointer with a function?
what is reason of your company position's in india no. 1.
Is null always equal to 0(zero)?
Define C in your own Language.
Why do we use null pointer?
Can you add pointers together? Why would you?
How does #define work?
how to find anagram without using string functions using only loops in c programming
How can you pass an array to a function by value?
Explain what is a stream?
What are called c variables?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)