how to find sum of digits in C?

Answer Posted / d. prashant

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the size of empty structure in c?

589


What are enumerated types?

646


How can I find out the size of a file, prior to reading it in?

616


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

1999


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

712






Explain why C language is procedural?

766


What is indirection in c?

620


Tell us the use of fflush() function in c language?

631


What are two dimensional arrays alternatively called as?

653


What is openmp in c?

608


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

2787


Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

3651


using for loop sum 2 number of any 4 digit number in c language

1728


hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

1895


What are the disadvantages of c language?

614