edited by
737 views
2 votes
2 votes
#include <stdio.h>
int gsum(int *a,int n)
{
    if(n<=0)
    return 0;
    else
    {
        if(*a%2==0)
        return *a+gsum(a+1,n-1);
        else
        return *a-gsum(a+1,n-1);
    }
}
int main(void) {
// your code goes here
int a[]={12,7,13,4,11,6};
printf("%d",gsum(a,6));
return 0;
}
edited by

2 Answers

Best answer
5 votes
5 votes
It will executed from last . Answer will be 15

12+gsum(a+1,5) 12+3=15

        |

      7-gsum(a+1,4) =7-4=3

             |

          13-gsum(a+1,3) =13-9=4

                 |

              4+gsum(a+1,2) =4+5=9

                    |

                 11-gsum(a+1,1) =11-6=5

                         |

                      6+gsum(a+1,0) =6+0=6

                            |

                           0
selected by

Related questions

0 votes
0 votes
1 answer
1
Rohit Gupta 8 asked Nov 8, 2017
7,116 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...
0 votes
0 votes
1 answer
2
Desert_Warrior asked May 16, 2016
2,358 views
#include<stdio.h int main() { int a = 5; int b = ++a * a++; printf("%d ",b); return 0; }(a) 25 (b) 30 (c) 36 (d) Undefined Behavior
0 votes
0 votes
2 answers
3
Desert_Warrior asked May 16, 2016
8,908 views
#include<stdio.h int main() { int a = 5; switch(a) { default: a = 4; case 6: a ; case 5: a = a+1; case 1: a = a-1; } printf("%d \n",a); return 0; }(a) 5 (b) 4 (c) 3 (d) N...
0 votes
0 votes
2 answers
4