• Please review our updated Terms and Rules here

Fibonacci Numbers with Turbo Pascal 3.

CP/M User

Veteran Member
Joined
May 2, 2003
Messages
2,986
Location
Back of Burke (Guday!), Australia
Hello,

I've stumbled across an unusual problem with this following program while using Turbo Pascal 3:


Code:
program fibonacci;

function fib(n:integer): integer;
begin
    if (n <= 2) then
        fib := 1
    else
        fib := fib(n-1) + fib(n-2);
end;

var
    i:integer;

begin
    for i := 1 to 16 do
        write(fib(i), ', ');
    writeln('...');
end.


The problem being the correct sequence of numbers isn't being produced. It's starts fine with 1, 1, but then it counts up to 15. The code is on Progopedia and includes Turbo Pascal 3 as part of the compilers which can compile. I'm using the CP/M version which has been tweaked for the Amstrad CPC computers, so I'm assuming it works correctly for the 16bit versions, but don't know if other CP/M versions of TP3 are struggling with this?
 
Back
Top