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 can I remove the leading spaces from a string?
What is the difference between strcpy() and memcpy() function in c programming?
Explain how many levels deep can include files be nested?
How will you write a code for accessing the length of an array without assigning it to another variable?
Why is c called c not d or e?
Why is C language being considered a middle level language?
How many types of functions are there in c?
What is the difference between void main and main in c?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
What is equivalent to ++i+++j?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
What language is windows 1.0 written?
Is c procedural or object oriented?
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above