how to find sum of digits in C?

Answer Posted / jay soni

#include<stdio.h>
#include<conio.h>
void main()

{
int n,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("\nsum of digits is %d",sum);

getch();
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the advantage of a random access file?

670


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

786


What is a good way to implement complex numbers in c?

600


Can you explain the four storage classes in C?

646


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

590






Do you know pointer in c?

595


explain what is fifo?

636


Why we use break in c?

556


What is the use of getchar functions?

680


How can I split up a string into whitespace-separated fields?

573


What is the function of multilevel pointer in c?

674


How do I copy files?

625


What is chain pointer in c?

605


How can a process change an environment variable in its caller?

658


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

878