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
Explain how can you avoid including a header more than once?
Is python a c language?
Explain the advantages of using macro in c language?
What is use of integral promotions in c?
What is wrong with this program statement? void = 10;
What are the advantages of c language?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
Can we assign string to char pointer?
What are the complete rules for header file searching?
What are variables and it what way is it different from constants?
What is the maximum no. of arguments that can be given in a command line in C.?
Can you define which header file to include at compile time?
What is getch () for?
Write a code to generate divisors of an integer?
Explain what does a function declared as pascal do differently?