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
What are actual arguments?
What is the explanation for modular programming?
What are header files in c?
What is a program flowchart and how does it help in writing a program?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the difference between Printf(..) and sprint(...) ?
FILE PROGRAMMING
What is a constant and types of constants in c?
Explain a pre-processor and its advantages.
How can you read a directory in a C program?
What are lookup tables in c?
Describe the order of precedence with regards to operators in C.
Give differences between - new and malloc() , delete and free() ?
What language is lisp written in?
What is a pragma?