CONTOH PROGRAM DERET GENAP
program deret_genap;
uses wincrt;
var
i:integer;
begin
i:=2; write(2,' ');
repeat
i:=i+2; write(i,' ');
until i=10;
end.
CONTOH PROGRAM URUT SATU KE SEPULUH
program urut_satu_ke_sepuluh;
uses wincrt ;
var
i:integer;
begin writeln(1);
i := 1;
repeat
i := i+1;
writeln (i);
until i=10 ;
end.
CONTOH PROGRAM DERET FIBONACCI
program deret_fibonacci;
uses wincrt;
function fibonacci(n:integer):integer;
begin
if n=0 then fibonacci:=0
else
if n=1 then fibonacci:=1
else
fibonacci:=fibonacci(n-1)+fibonacci(n-2);
end;
var
n, jumlah:integer;
begin
Write('Masukkan bilangan: ');readln(n);
for n:= 1 to n do
Writeln('Deret Fibonacci ke-',n,' adalah: ',fibonacci(n));
for n:= 1 to n do
jumlah:=fibonacci(n) + fibonacci(n)+ fibonacci(n-1)-1;
writeln('==================================');
writeln('jumlah fibonacci ke-’,n,’ adalah: ',jumlah);
readkey;
donewincrt;
end.
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar