Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int rec(int number) {
- if(number == 0) {
- return 0;
- }
- int digit = number % 10;
- return rec(number / 10) + digit;
- }
- int main() {
- cout << rec(1304) << endl;
- return 0;
- }
- // rec(1304) = rec(130) + 4 = 4 + 4 = 8
- // rec(130) = rec(13) + 0 = 4 + 0 = 4
- // rec(13) = rec(1) + 3 = 1 + 3 = 4
- // rec(1) = rec(0) + 1 = 0 + 1 = 1
- // rec(0) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement