Advertisement
Josif_tepe

Untitled

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