Advertisement
Josif_tepe

Untitled

Oct 6th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int zbir(int broj) {
  8.     if(broj == 0) {
  9.         return 0;
  10.     }
  11.     int cifra = broj % 10;
  12.     return zbir(broj / 10) + cifra;
  13. }
  14. int main() {
  15.    cout <<  zbir(134) << endl;
  16.     return 0;
  17. }
  18. // zbir(134) = zbir(13) + 4 = 4 + 4 = 8
  19. // zbir(13) = zbir(1) + 3 = 1 + 3 = 4
  20. // zbir(1) = zbir(0) + 1 = 0 + 1 = 1
  21. // zbir(0) = 0
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement