Program to find the sum of digits of a given number until
the sum becomes a single digit
Answer Posted / t. ashok kumar
//Sum of digits of a number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,r,m;
int s=0;
cout<<"Sum of digits of a number:-\n";
cout<<"Enter the number: ";
cin>>n;
m=n;
repeat:
while (n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
if(s>9)
{
n=s;
s=0;
goto repeat;
}
cout<<"Sum of digits of the number "<<m<<" is "<<s;
getch();
}
| Is This Answer Correct ? | 14 Yes | 6 No |
Post New Answer View All Answers
write a program fibonacci series and palindrome program in c
How can a number be converted to a string?
writ a program to compare using strcmp VIVA and viva with its output.
How the c program is executed?
What type is sizeof?
What are the data types present in c?
What does == mean in texting?
What is multidimensional arrays
What is pointer to pointer in c with example?
Why should I use standard library functions instead of writing my own?
What is the size of empty structure in c?
What is the difference between c and python?
What would be an example of a structure analogous to structure c?
Differentiate between calloc and malloc.
Write a program that accept anumber in words