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 is volatile variable in c with example?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What are the different file extensions involved when programming in C?
Write a program to print factorial of given number using recursion?
Explain how do you determine a file’s attributes?
Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"
What is getch c?
How old is c programming language?
What is a pointer and how it is initialized?
What is void c?
Can we assign string to char pointer?
What is NULL pointer?
Differentiate between full, complete & perfect binary trees.
What are external variables in c?
Tell me what is null pointer in c?