Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int rec(int number) {
- if(number == 0) {
- return 0;
- }
- int cifra = number % 10;
- return rec(number / 10) + cifra;
- }
- int main()
- {
- int broj;
- cin >> broj;
- cout << rec(broj) << endl;
- return 0;
- }
- /*
- rec(4313) = rec(431) + 3 = 8 + 3 = 11
- rec(431) = rec(43) + 1 = 7 + 1 = 8
- rec(43) = rec(4) + 3 = 4 + 3 = 7
- rec(4) = rec(0) + 4 = 0 + 4 = 4
- rec(0) = 0
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement