Welcome..!!

Please visit http://csprograms.in/ for more Computer Science programs.

Tuesday 13 March 2012

2. C++ program to find the sum of digits of a given number.

#include <iostream>
int main()
{
int s,n,n1;
cout <<"enter the number \n";
s=0;
cin >>n;
cout <<"the given number is \n"<<n;
a: do
{
n1=n%10;
s=s+n1;
n=n/10;
}
while (n!=0);
if(s>9)
{
n=s;
s=0;
goto a;
}
else
cout <<"sum of digit is \n"<<s;

return 0; 
}

No comments:

Post a Comment