-
Consider the program below :
#include < stdio.h >
int fun (int n, int * f_p){
int t, f;
if (n < = 1) {
*f_p = 1
return 1;
}
t = fun (n – 1, *f_p);
f = t + *f_p; *f_p = t;
return f;
}
int main () {
int x = 15;
printf (“% d\n”, fun (5, & x));
return 0;
}
The value printed is
-
- 6
- 8
- 14
- 15
- 6
Correct Option: B
The program calculates nth Fibonacci Number. The statement t = fun (n-1, fp) gives the (n-1)th Fibonacci number and *fp is used to store the (n-2)th Fibonacci Number. Initial value of *fp (which is 15 in the above program) doesn't matter. Following recursion tree shows all steps from 1 to 10, for exceution of fun(5, &x).