need reply

i have a cut of program like this:
procedure Bingo(t);
begin
if(t<2)then
writeln('Bingo')
else
beigin
Bingo(t-1);
Bingo(t-2)
end;
end;
when the program called bingo(6) why the answer is 13?
please explain me the way

Comments

  • As part of the procedure there are 2 calls to itself as part of the else condition. When the procedure goes through all of the recursive calls to the procedure, the numbers are decreased for the variable 't' and when 't' gets to 1 then the "Bingo" is output on the screen. Go through the recursive calls or use the debugger to see the stack and it comes out to 13 times that "Bingo" is put on the screen. As an aside, this the Fibonacci series when you look at the series of numbers.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion