Advertisement
999ms

Untitled

Oct 1st, 2020
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int x;
  7.     cin >> x;
  8.     while (x >= 10) {
  9.         int ans = 0;
  10.         while (x > 0) {
  11.             ans += x % 10;
  12.             x /= 10;
  13.         }
  14.         x = ans;
  15.     }
  16.     cout << x << '\n';
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement