how to find sum of digits in C?

Answer Posted / bhagwat

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}

Is This Answer Correct ?    53 Yes 19 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does c have function or method?

586


What is the main difference between calloc () and malloc ()?

568


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

631


Explain how can I right-justify a string?

618


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

640






What does node * mean?

705


Are there any problems with performing mathematical operations on different variable types?

569


Can you write the function prototype, definition and mention the other requirements.

656


What is the difference between void main and main in c?

621


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

617


Is c easier than java?

567


What is a lookup table in c?

622


Stimulate calculator using Switch-case-default statement for two numbers

2444


In C language, a variable name cannot contain?

737


Was 2000 a leap year?

626