Advertisement
Josif_tepe

Untitled

Dec 10th, 2022
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int rekurzija(int x) {
  5.     if(x == 0) {
  6.         return 0;
  7.     }
  8.     return rekurzija(x / 10) + (x % 10);
  9. }
  10. int main() {
  11.     int n;
  12.     scanf("%d", &n);
  13.     printf("%d", rekurzija(n));
  14.    
  15.     return 0;
  16. }
  17. /*
  18.  rekurzija(124) --> rekurzija(12) + 4 = 3 + 4 = 7
  19.  rekurzija(12) --> rekurzija(1) + 2 = 1 + 2 = 3
  20.  rekurzija(1) --> rekurzija(0) + 1 = 0 + 1 = 1
  21.  rekurzija(0) --> 0
  22.  
  23.  
  24.  */
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement