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
What does the c in ctime mean?
How to write c functions that modify head pointer of a linked list?
What is derived datatype in c?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
How do you construct an increment statement or decrement statement in C?
What is the size of enum in bytes?
What is the c language function prototype?
Is c procedural or functional?
What is huge pointer in c?
What are the types of bitwise operator?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
Differentiate between full, complete & perfect binary trees.
What is far pointer in c?
What is function pointer c?
What are shell structures used for?