Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //P96965 Reducció de dígits
- #include <iostream>
- using namespace std;
- int suma_digits(int x) {
- if(x < 10) return x;
- else return x%10 + suma_digits(x/10);
- }
- int reduccio_digits(int x) {
- if(x < 10) return x;
- else return reduccio_digits(suma_digits(x));
- }
- int main() {
- int x;
- cin >> x;
- cout << reduccio_digits(x) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement