Gate CS-2007 Question Paper With Solutions

Q. 77 Consider the following C function:

#include <stdio.h> 
int f(int n) 
{ 
    static int r = 0; 
    if (n <= 0) return 1; 
    if (n > 3) 
    { 
        r = n; 
        return f(n-2)+2; 
    } 
    return f(n-1)+r; 
} 
  
int main() 
{ 
    printf("%d", f(5)); 
}

What is the value of f(5) ?

(A) 5

(B) 7

(C) 9

(D) 18

Answer: (D)

Explanation:

Gate CS-2007 Question Paper With Solutions

Learn More:   Gate EE-2015-1 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here