25/11/13

Sahabat-sahabatku ada contoh program fibbonaci nih :) Semoga bermanfaat...

program asti_fibbonaci;
uses wincrt;
var a,b,i:byte;
    j:string;

function fib(x:byte):longint;
begin
if (x=1) or (x=2) then fib:=1
else
    fib:=fib(x-2)+fib(x-1);
end;

begin
repeat
begin
clrscr;
writeln('..:::Mencetak deret fibbonaci:::..');
write('Masukkan batas bawah= ');readln(a);
write('Masukkan batas atas = ');readln(b);
if (a>b) then writeln('Batas yang Anda masukkan salah!')
else
begin
writeln('Deretnya adalah: ');
for i:=a to b do
write(fib(i):5);
writeln;
end;
end;
writeln;
writeln;
write('Coba lagi? (y/t) ');readln(j);
until (j<>'y');
end.

Hasil Running

0 komentar :

Posting Komentar