Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sum_digits(int n) {
- int r = 0;
- while (n > 0) {
- r = r + (n%10);
- n = n/10;
- }
- if (r < 10) return r;
- else return sum_digits(r);
- }
- int reduction_of_digits(int x) {
- if (x < 10) return x;
- else {
- int z = sum_digits(x);
- return z;
- }
- }
- int main() {
- int x;
- while (cin >> x) {
- cout << reduction_of_digits(x) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement