Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 101
- /// parniilineparni = 1 znaci parni pozicii
- /// parniilineparni = 0 znaci neparni pozicii
- int rekurzija(int *niza, int parni_ili_neparni, int i){
- if(i == -1) {
- return 0;
- }
- int dodadi = 0;
- if(parni_ili_neparni == 1) {
- if(i % 2 == 0) {
- dodadi = niza[i];
- }
- }
- else {
- if(i % 2 == 1) {
- dodadi = niza[i];
- }
- }
- return rekurzija(niza, parni_ili_neparni, i - 1) + dodadi;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- int niza[101];
- int brojac = 1;
- for(int i = 0; i < n; i++) {
- int sz;
- scanf("%d", &sz);
- for(int j = 0; j < sz; j++) {
- scanf("%d", &niza[j]);
- }
- printf("%d\n", rekurzija(niza, brojac % 2, sz - 1));
- brojac += 1;
- }
- return 0;
- }
- /*
- 3
- 4 1 2 3 4
- 5 7 8 6 5 4
- 2 1 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement