Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
need reply Posted by dydrax on 9 May 2011 at 1:21 AM
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
Report
Re: need reply Posted by quikcarl on 10 May 2011 at 8:55 PM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.