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
Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?
What are global variables and explain how do you declare them?
Is null always defined as 0(zero)?
What is declaration and definition in c?
count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array
Explain what does a function declared as pascal do differently?
What is the use of ?
provide an example of the Group by clause, when would you use this clause
How main function is called in c?
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
How can you convert integers to binary or hexadecimal?
What is meant by high-order and low-order bytes?
Define C in your own Language.
Are the variables argc and argv are always local to main?