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
Explain pointer. What are function pointers in C?
Why is structure padding done in c?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm
Can include files be nested?
What is a const pointer in c?
What are pointers really good for, anyway?
Can you assign a different address to an array tag?
Why clrscr is used in c?
How can you avoid including a header more than once?
What does void main return?
Can a variable be both const and volatile?
Why isnt there a numbered, multi-level break statement to break out
What are the types of bitwise operator?
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
Explain what is wrong with this program statement?