Fibonacci numbers in Pascal
Example for versions
Free Pascal 2.0.4,
Free Pascal 2.2.0,
Turbo Pascal 1.0,
Turbo Pascal 2.0,
Turbo Pascal 3.0,
Turbo Pascal 4.0,
Turbo Pascal 5.0,
Turbo Pascal 5.5,
Turbo Pascal 6.0,
Turbo Pascal 7.0,
gpc 20070904
This example uses recursive definition of Fibonacci numbers.
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.
Comments
]]>blog comments powered by Disqus
]]>