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


Please Help Members By Posting Answers For Below Questions

What does the c in ctime mean?

576


How to write c functions that modify head pointer of a linked list?

550


What is derived datatype in c?

643


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1527


How do you construct an increment statement or decrement statement in C?

751






What is the size of enum in bytes?

596


What is the c language function prototype?

655


Is c procedural or functional?

593


What is huge pointer in c?

589


What are the types of bitwise operator?

669


How will you declare an array of three function pointers where each function receives two ints and returns a float?

787


Differentiate between full, complete & perfect binary trees.

680


What is far pointer in c?

817


What is function pointer c?

593


What are shell structures used for?

606