Advertisement
Josif_tepe

Untitled

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