Advertisement
Ausdauer

P96965 Reducció de dígits

Jun 10th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. //P96965 Reducció de dígits
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int suma_digits(int x) {
  6.     if(x < 10) return x;
  7.     else return x%10 + suma_digits(x/10);
  8. }
  9. int reduccio_digits(int x) {
  10.     if(x < 10) return x;
  11.     else return reduccio_digits(suma_digits(x));
  12. }
  13. int main() {
  14.     int x;
  15.     cin >> x;
  16.     cout << reduccio_digits(x)  << endl;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement