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
What are the key features in c programming language?
Is it possible to initialize a variable at the time it was declared?
Difference between linking and loading?
Explain the difference between getch() and getche() in c?
Who is the founder of c language?
What is putchar() function?
What is %g in c?
What is data type long in c?
What is extern keyword in c?
Function calling procedures? and their differences? Why should one go for Call by Reference?
When should a type cast be used?
provide an example of the Group by clause, when would you use this clause
How do I get an accurate error status return from system on ms-dos?
What is the difference between array and structure in c?
Explain what is wrong with this statement? Myname = ?robin?;