Program to find the sum of digits of a given number until
the sum becomes a single digit

Answer Posted / ashutosh shashi

int n = 123456789; //any numer of you want sum
int sum = 0;
while (n > 0)
{
int p = n % 10;
sum = sum + p;
n = n / 10;
if(n==0 && sum>9)
{
n=sum;
sum=0;
}
}
printf("%d",sum);

Is This Answer Correct ?    157 Yes 63 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain pointer. What are function pointers in C?

624


Why is structure padding done in c?

639


hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm

1631


Can include files be nested?

624


What is a const pointer in c?

668






What are pointers really good for, anyway?

610


Can you assign a different address to an array tag?

696


Why clrscr is used in c?

579


How can you avoid including a header more than once?

563


What does void main return?

599


Can a variable be both const and volatile?

669


Why isnt there a numbered, multi-level break statement to break out

585


What are the types of bitwise operator?

657


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

2528


Explain what is wrong with this program statement?

618