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

How can I remove the leading spaces from a string?

630


What is the difference between strcpy() and memcpy() function in c programming?

626


Explain how many levels deep can include files be nested?

622


How will you write a code for accessing the length of an array without assigning it to another variable?

611


Why is c called c not d or e?

604






Why is C language being considered a middle level language?

652


How many types of functions are there in c?

581


What is the difference between void main and main in c?

621


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

622


What is equivalent to ++i+++j?

641


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

631


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1504


What language is windows 1.0 written?

571


Is c procedural or object oriented?

573


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

656