PROGRAM FAKTORIAL PAKAI FOR TO DO
program faktorial;
uses wincrt;
var
i,n,f:integer;
begin
readln(n); f:=1;
for i:=1 to n do
begin
f:=f*i;
end;
writeln(n,' faktorial = ',f);
end.
PROGRAM FAKTORIAL PAKAI REPEAT UNTIL
program faktorial;
uses wincrt;
var
i,n,f:integer;
begin
write('masukkan nilai n = '); read(n);
f:=1; i:=0;
repeat
i:=i+1;
f:=f*i;
until i=n;
writeln(n,' faktorial = ',f);
end.
PROGRAM FAKTORIAL PAKAI WHILE DO
program faktorial;
uses wincrt;
var
i,n,f:integer;
begin
writeln('masukkan nilai = ');readln(n);
f:=1;
while i<n do
begin i:=i+1;
f:=f*i;
end;
write(n,' faktorial= ',f);
end.
PROGRAM FAKTORIAL PAKAI IF REPEAT
program faktorial;
uses wincrt;
var
i,n:integer;
f: real;
begin
readln(n);f:=1;i:=0;
if (n=0) then
writeln(1)
else
repeat
i:=i+1;
f:=f*i;
until i=n;
writeln(n,'faktorial=',f);
end.
PROGRAM FAKTORIAL MODEL PERKALIAN
program faktorial;
uses wincrt;
var
i,a,n,f:integer;
begin
write('faktorial dari '); read(n);
f:=1; i:=0;
if (n>1)then
begin
repeat
i:=i+1;
f:=f*i;
until i=n;
a:=n;
for i:=n downto 2 do
begin
write (a,'x');
a:=a-1;
end;
write(1,'=',f)
end
else
if (n=0)then writeln ('1') else
if (n=1)then writeln ('1') else
writeln ('tidak terdifinisi')
end.
PROGRAM PERMUTASI DAN KOMBINASI
program permutasi_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.
Tidak ada komentar:
Posting Komentar