What is the value of F(4) using the following procedure: function F(K :…
2008
What is the value of F(4) using the following procedure:
function F(K : integer)
integer;
begin
if (k<3) then F:=k
else F:=F(k-1)*F(k-2)+F(k-3)
end;- A.
5
- B.
6
- C.
7
- D.
8
Attempted by 48 students.
Show answer & explanation
Correct answer: A
First, identify base cases where k < 3: F(0)=0, F(1)=1, and F(2)=2. Next, calculate F(3) using the recursive formula: F(3) = F(2)*F(1) + F(0) = 2*1 + 0 = 2. Finally, calculate F(4): F(4) = F(3)*F(2) + F(1) = 2*2 + 1 = 5.