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 to find whether the given number or string is palindrome.
Find MAXIMUM of three distinct integers using a single C statement
write an algorithm to display a square matrix.
Where define directive used?
How do you generate random numbers in C?
How can I read in an object file and jump to locations in it?
In C language, a variable name cannot contain?
Why array is used in c?
What is the value of h?
a program that can input number of records and can view it again the record
Explain how do you determine the length of a string value that was stored in a variable?
What does #pragma once mean?
How do you define structure?
can we have joblib in a proc ?
Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?