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 the maximum length of an identifier?
Why main function is special give two reasons?
Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
Can we assign integer value to char in c?
How pointers are declared?
What is null in c?
What is the function of this pointer?
Define Spanning-Tree Protocol (STP)
What are different storage class specifiers in c?
write a program to concatenation the string using switch case?
What does stand for?
What are the different types of control structures?
What is nested structure?
Are there any problems with performing mathematical operations on different variable types?