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