// UVa 11332 - Summing Digits
#include <iostream>
using namespace std;
#define datatype unsigned long long int
datatype sum_digs(datatype n) {
datatype s = 0;
while (n > 0) {
s += n % 10;
n /= 10;
}
return s;
}
int main() {
datatype n;
cin >> n;
while (n) {
while (n >= 10)
n = sum_digs(n);
cout << n << endl;
cin >> n;
}
return 0;
}
No comments:
Post a Comment