UVa Problem 11332
Summing Digit
Problem link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2307
Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,sum;
while(cin >> n, n != 0)
{
if (n<10)
cout<<n<<endl;
if (n>9)
{
while (n>9)
{
sum=0;
while (n>0 )
{
sum=sum+n%10;
n=n/10;
}
sum=n+sum;
}
cout<<sum<<endl;
}
}
return 0;
}
No comments:
Post a Comment