in Programming in C edited by
464 views
1 vote
1 vote

What is the value of $f(4)$ using the following $C$ code:

int f(int k){
    if(k<3)
        return k;
    else
        return f(k-1) * f(k-2) + f(k-3);
}
  1. $5$
  2. $6$
  3. $7$
  4. $8$
in Programming in C edited by
464 views

1 comment

$f(0)$ $0$
$f(1)$ $1$
$f(2)$ $2$
$f(3)$ $2$
$f(4)$ $5$

 $f(4)=f(3)*f(2)+f(1)=2*2+1=5$

Option $(A)$ is correct.

4
4

Please log in or register to answer this question.

Related questions