Untitled

mail@pastecode.io avatar
unknown
c_cpp
17 days ago
413 B
0
Indexable
Never
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int rec(int x) {
    if(x == 0) {
        return 0;
    }
    int cifra = x % 10;
    return rec(x / 10) + cifra;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cout << rec(123) << endl;
   return 0;
}
// rec(123) = rec(12) + 3 = 3 + 3 = 6
// rec(12) = rec(1) + 2 = 1 + 2 = 3
// rec(1) = rec(0) + 1 = 0 + 1 = 1
// rec(0) = 0
Leave a Comment