Friday, June 25, 2010

deret fibonacci dengan pascal

program mencari deret fibonacci
tak buat di dua versi, TPW sama FPC:

dibuat di TPW:

program deret_fibonacci;

uses wincrt;

var a,b,c: integer;

function fibonacci (var i :integer): integer;

var j,k:integer;
begin
j:=i-1;
k:=i-2;
if ((i=1) or (i=2)) then
fibonacci:=1
else
fibonacci:=fibonacci(j)+fibonacci(k);
end;

begin
writeln('masukkan banyaknya bilangan fibonacci : ');
readln(a);

for b:=1 to a do
write(fibonacci(b),' ');


end.


nah yang ini ane buat di FPC

program deret_fibonacci;

uses crt;

var a,b,c: integer;

function fibonacci (var i :integer): integer;

var j,k:integer;
begin
clrscr;
j:=i-1;
k:=i-2;
if ((i=1) or (i=2)) then
fibonacci:=1
else
fibonacci:=fibonacci(j)+fibonacci(k);
end;

begin
writeln('masukkan banyaknya bilangan fibonacci : ');
readln(a);
b:=0;
repeat
b:=b+1;
write(fibonacci(b),' ');
until(b>a);
readln;

end.

No comments: