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.
CONTOH 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.
CONTOH 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.
CONTOH 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.
CONTOH 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.
0 komentar:
Posting Komentar