Deret Fibonacci Menggunakan Rekursif
Berikut koding untuk program deret fibonacci menggunakan bahasa pemrograman pascal
Program Deret_Fibonacci;
uses crt;
var
i,n : integer;
function fib(n : integer) : integer;
begin
if (n = 0) then
fib := 0
else if (n = 1) then
fib := 1
else
fib := fib(n-1) + fib(n-2);
end;
begin
clrscr;
writeln('Program Deret Fibonacci');
writeln;
write('Masukkan Jumlah Deret : ');readln(n);
write('Deret Fibonacci ',n,' Deret : ');
for i := 0 to n-1 do
write(fib(i),' ');
readln;
end.
Output Program
Program Deret_Fibonacci;
uses crt;
var
i,n : integer;
function fib(n : integer) : integer;
begin
if (n = 0) then
fib := 0
else if (n = 1) then
fib := 1
else
fib := fib(n-1) + fib(n-2);
end;
begin
clrscr;
writeln('Program Deret Fibonacci');
writeln;
write('Masukkan Jumlah Deret : ');readln(n);
write('Deret Fibonacci ',n,' Deret : ');
for i := 0 to n-1 do
write(fib(i),' ');
readln;
end.
Output Program
Deret Fibonacci Menggunakan Rekursif
Reviewed by Ardiansyahsw
on
05.42
Rating:
Tidak ada komentar: