CONTOH PROGRAM PERMUTASI DAN KOMBINASI
uses wincrt;
var
a,b,a_k,kombinasi,permutasi:real;
i,n,k:longint;
begin
writeln('MENGHITUNG PERMUTASI DAN KOMBINASI:');
write('masukkan bilangan n= ');readln(n);
write('masukkan bilangan k= ');readln (k);
a:=1;
b:=1;
a_k:=1;
for i:=2 to n do
a := a*i;
for i:=2 to k do
b :=b*i;
for i :=2 to (n-k) do
a_k := a_k * i;
kombinasi := a/(b*a_k);
permutasi :=a/ (a_k);
writeln ( n, ' Kombinasi',k,' = ', kombinasi:4:1);
writeln (n, ' Permutasi',k,' = ',permutasi :4:1);
end.
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 DERET GANJIL
Program Deret;
Uses Crt;
Var
a,b,n:integer;
Uses Crt;
Var
a,b,n:integer;
begin
a:=1;
b:=1;
write('Jumlah Digit Deret yang anda inginkan: '); readln(n);
writeln;
while (b<=n) do
begin
write(a,' ');
a:=a+2 ;
b:=b+1 ;
end;
writeln;
writeln;
writeln('Jumlah beluruh deretnya adalah : ',sqr(n));
readln()
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.
CONTOH DERET ARIMATIKA
program deret_aritmatika;
uses wincrt;
var
a,b,n,u:integer;
s:real;
begin
writeln(‘PROGRAM DERET ARITMATIKA’);
writeln(‘————————’);
write(‘a =’);readln(a);
write(‘b =’);readln(b);
write(‘n =’);readln(n);
s:=n*((2*a)+((n-1)*b))/2;
u:=a+((n-1)*b);
writeln(‘Un=’,u);
writeln(‘Sn=’,s:10:2);
end.
0 komentar:
Posting Komentar