edited by
12,051 views
27 votes
27 votes

What is the value printed by the following C program?

#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);
}

int main()
{
    int a[] = {12, 7, 13, 4, 11, 6};
    printf("%d", f(a, 6));
    return 0;
}
  1. $-9$
  2. $5$
  3. $15$
  4. $19$
edited by

5 Answers

Answer:

Related questions

5.7k
views
2 answers
18 votes
go_editor asked Apr 21, 2016
5,726 views
Consider the following recursive C function that takes two arguments.unsigned int foo(unsigned int n, unsigned int r) { if (n>0) return ((n%r) + foo(n/r, r)); else return 0; ... text{foo}$ when it is called as $\text{foo(513, 2)}$?$9$8$5$2$
9.1k
views
3 answers
18 votes
go_editor asked Sep 29, 2014
9,139 views
Consider the following recursive C function that takes two arguments.unsigned int foo(unsigned int n, unsigned int r) { if (n>0) return ((n%r) + foo(n/r, r)); else return 0; ... {foo}$ when it is called as $\text{foo(345, 10)}$?$345$12$5$3$
14.2k
views
6 answers
30 votes
Kathleen asked Sep 25, 2014
14,244 views
What value would the following function return for the input $x=95$?Function fun (x:integer):integer; Begin If x > 100 then fun = x – 10 Else fun = fun(fun (x+11)) End;$89$90$91$92$
13.6k
views
5 answers
27 votes
Kathleen asked Sep 22, 2014
13,554 views
Consider the following C-program:void foo (int n, int sum) { int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n/10; sum = sum + k; foo (j, sum); printf ("%d,",k); } ... }$\text{8, 4, 0, 2, 0}$\text{2, 0, 4, 8, 14}$\text{2, 0, 4, 8, 0}$