Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <cmath>
- #include <vector>
- using namespace std;
- int rec(int x) {
- if(x == 0) {
- return 0;
- }
- int cifra = x % 10;
- return cifra + rec(x / 10);
- }
- int main()
- {
- cout << rec(1234) << endl;
- return 0;
- }
- // rek(1234) = 4 + rec(123) = 4 + 6 = 10
- // rec(123) = 3 + rec(12) = 3 + 3 = 6
- // rec(12) = 2 + rec(1) = 2 + 1 = 3
- // rec(1) = 1 + rec(0) = 1 + 0 = 1
- // rec(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement