Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int zbir(int *niza, int n, int i) {
- if(i == n) {
- return 0;
- }
- return zbir(niza, n, i + 1) + 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", zbir(niza, n, 0));
- return 0;
- }
- // zbir(niza, n, 0) = zbir(niza, n, 1) + 1 = 14 + 1 = 15
- // zbir(niza, n, 1) = zbir(niza, n, 2) + 2 = 12 + 2 = 14
- // zbir(niza, n, 2) = zbir(niza, n, 3) + 3 = 9 + 3 = 12
- // zbir(niza, n, 3) = zbir(niza, n, 4) + 4 = 5 + 4 = 9
- // zbir(niza, n, 4) = zbir(niza, n, 5) + 5 = 0 + 5 = 5
- // zbir(niza, n, 5) = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement