Untitled

 avatar
unknown
c_cpp
a year ago
413 B
5
Indexable
#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
Editor is loading...
Leave a Comment