Answer Posted / keerthireddy
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum = %d",sum);
}
output:
3456
how it works as follows:
3456%10 means it gives reminder as 6
6 will be added to the sum
3456/10 means it gives quotient as 345
then again loop is executing until the n value is 0
finally the result as 6+5+4+3=18
| Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
Explain what is the benefit of using enum to declare a constant?
What is the difference between declaring a variable and defining a variable?
Function calling procedures? and their differences? Why should one go for Call by Reference?
Can an array be an Ivalue?
How to throw some light on the b tree?
Why is this loop always executing once?
What does c value mean?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What is integer constants?
What is optimization in c?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Is stack a keyword in c?
Explain the red-black trees?
How many types of arrays are there in c?
Describe static function with its usage?