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


Please Help Members By Posting Answers For Below Questions

How do you define CONSTANT in C?

640


How can I determine whether a machines byte order is big-endian or little-endian?

607


What is the difference between single charater constant and string constant?

611


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

581


Does free set pointer to null?

545






formula to convert 2500mmh2o into m3/hr

485


What are the different types of control structures?

570


What is the right type to use for boolean values in c?

570


What is c value paradox explain?

563


write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1

3240


What is the advantage of a random access file?

629


What is a volatile keyword in c?

627


What are the functions to open and close the file in c language?

581


How can I prevent another program from modifying part of a file that I am modifying?

599


What is sizeof c?

590