Gate CS-2008 Question Paper With Solutions

Q. 13 Consider the following C functions:

int f1 (int n)
{
If(n==0||n==1)
return n;
else
return(2)f1(n-1)+3)f1(n-2));
}
int f2(int n)
{
int i;
int X[N], Y[N], Z[N];
X[1]=1;Y[1]=2;Z[1]=3;
for (i=2;i<=n;i++){
X[i]=Y[i-1]+Z[i-2];
Y[i]=2)X[i];
z[i]=3)X[i];
}
return X[n];
}

f1 (8) f2 (8) return the values

(A) 1661 and 1640

(B) 59 and 59

(C) 1640 and 1640

(D) 1640 and 1661

Answer: (B) & (C)

Explanation:

Gate CS-2008 Question Paper With Solutions

Learn More:   Gate CS-2015-3 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here