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 / jyoti
#include<stdio.h>
int main()
{
int n,d1,d2,d3,d4,d5,s;
printf("enter a five digit no");
scanf("%d",&n);
d5=n%10;n=n/10;
d4=n%10;n=n/10;
d3=n%10;n=n/10;
d2=n%10;n=n/10;
d1=n%10;
s=d1+d2+d3+d4+d5;
return 0;
}
| Is This Answer Correct ? | 29 Yes | 13 No |
Post New Answer View All Answers
Describe the order of precedence with regards to operators in C.
How can I read/write structures from/to data files?
Can you please explain the difference between malloc() and calloc() function?
Explain what are multidimensional arrays?
What are pointers?
Explain what is the difference between far and near ?
How many keywords are there in c?
What is static volatile in c?
What is the general form of #line preprocessor?
What do you mean by dynamic memory allocation in c?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
How reliable are floating-point comparisons?
pierrot's divisor program using c or c++ code
What is action and transformation in spark?
How are pointers declared in c?