Program to find the sum of digits of a given number until
the sum becomes a single digit
Answer Posted / rama krishna sidhartha
int n = 1234; //any numer of you want sum
int sum = 0;
void main()
{
clrscr();
while (n > 0)
{
int p = n % 10;
sum = sum + p;
n = n / 10;
}
printf("%d",sum);
getch();
}
| Is This Answer Correct ? | 49 Yes | 75 No |
Post New Answer View All Answers
What is difference between Structure and Unions?
List a few unconditional control statement in c.
When is a null pointer used?
What is modeling?
What is variable and explain rules to declare variable in c?
What does the error message "DGROUP exceeds 64K" mean?
Once I have used freopen, how can I get the original stdout (or stdin) back?
What is const and volatile in c?
Explain how can I read and write comma-delimited text?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
What is the purpose of main( ) in c language?
What are dangling pointers? How are dangling pointers different from memory leaks?
Is return a keyword in c?
How can I manipulate strings of multibyte characters?
Write a program which returns the first non repetitive character in the string?