1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> int f(int *a,int n) { if(n<=0) { return 0; } else if( *a%2==0) { return *a+f(a+1,n-1); } else { return *a-f(a+1,n-1); } } main() { int a[]={12,7,13,4,11,6}; printf("\nsum is = %d ",f(a,6)); return 0; } |
f is a recursive function, after solving the function we will get the value 15 as output
12 + (7 – (13 – (4 + (11 – (6+0))))) = 15.