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 use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.
What is calloc malloc realloc in c?
Who invented b language?
Find MAXIMUM of three distinct integers using a single C statement
How do you determine a file’s attributes?
why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above
Apart from dennis ritchie who the other person who contributed in design of c language.
What is a stream?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
How do you sort filenames in a directory?
When should the const modifier be used?
i got 75% in all semester am i eligible for your company
HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????
How do you define CONSTANT in C?