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
How do we make a global variable accessible across files? Explain the extern keyword?
What are the rules for the identifier?
Explain logical errors? Compare with syntax errors.
What is indirection? How many levels of pointers can you have?
Why clrscr is used after variable declaration?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
Can a function argument have default value?
how should functions be apportioned among source files?
Which of these functions is safer to use : fgets(), gets()? Why?
What is scanf_s in c?
Explain how can I manipulate strings of multibyte characters?
Is c dynamically typed?
What is scanf () in c?
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
What is operator precedence?