Advertisement
Josif_tepe

Untitled

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