Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- int rek(int *niza, int n, int i) {
- if(i >= n) {
- return 0;
- }
- if(niza[i] < 0) {
- return 0;
- }
- if(niza[i] == 0) {
- return rek(niza, n, i + 1);
- }
- return rek(niza, n, i + niza[i]) + niza[i];
- }
- int main() {
- int n;
- scanf("%d", &n);
- int niza[n];
- for(int i = 0; i < n; i++) {
- scanf("%d", &niza[i]);
- }
- printf("%d\n", rek(niza, n, 0));
- return 0;
- }
- /*
- 2 0 3 1 4 5 6 2 10 11
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement