Berikut beberapa program pascal, silahkan dicoba. :)
program deret_no2;
uses crt;
var
d,e,n : integer;
begin
clrscr;
writeln ('Banyak data: ');
readln (n);
writeln ('Deret :');
d:=1;
e:=1;
while e<=n do
begin
writeln(d);
d:=d*3;
e:=e+1;
end;
writeln;
readln;
end.
============================================================
program persegipanjang_no3;
uses crt;
var
p,l,x,y:integer;
begin
clrscr;
write('panjang: ');
readln(p);
write('lebar: ');
readln(l);
clrscr;
begin
for y:=1 to l do
begin
for x:=1 to p do
begin
if x=1 then write ('*') else
if y=1 then write ('*') else
if x=p then write ('*') else
if y=l then write ('*') else
write (' ');
end;
writeln;
end;
end;
readln;
end.
=============================================================
program tampil_4a;
uses crt;
var
i,j:integer;
begin
clrscr;
i:=1;
while i<=4 do
begin
j:=1;
while j<=3 do
begin
write (i);
j:=j+1
end;
writeln;
i:=i+1
end;
readln;
end.
==============================================================
program tampil_4b;
uses crt;
var
i,j:integer;
begin
clrscr;
i:=1;
while i<=4 do
begin
j:=1;
while j<=i do
begin
write (i);
j:=j+1
end;
writeln;
i:=i+1
end;
readln;
end.
===============================================================
program tampil_4c;
uses crt;
var
i,j:integer;
begin
clrscr;
i:=1;
while i<=4 do
begin
j:=1;
while j<=i do
begin
write (j);
j:=j+1
end;
writeln;
i:=i+1
end;
readln;
end.
===================================================================
program tampil_4d;
uses crt;
var
i,j:integer;
begin
clrscr;
i:=1;
while i<=4 do
begin
j:=i;
while j>=1 do
begin
write (j);
j:=j-1
end;
writeln;
i:=i+1
end;
readln;
end.
=====================================================================
program pangkat_5a;
uses crt;
var
i,n,x,y:integer;
begin
clrscr;
write ('Masukan nilai: ');
readln (x);
write ('Masukan pangkat: ');
readln (y);
i:=1;
n:=1;
while i<=y do
begin
n:=n*x;
i:=i+1;
end;
write ('Hasil Pangkat : ',n);
readln;
end.
========================================================================
program faktorial_5b;
uses crt;
var
i,n,f:integer;
begin
clrscr;
writeln ('Masukan Data: ');
readln (n);
f:=1;
while i<n do
begin i:=i+1;
f:=f*i;
end;
write (n,'!',' ','=',' ',(f));
readln;
end.
========================================================================
program ratarata_5c;
uses crt;
var
n,x,i,total:integer;
mean:real;
begin
clrscr;
write ('Banyak Data: ');
readln(n);
i:=1;
writeln;
while i<=n do
begin
write ('Nilai Data ke-',i,':');
readln(x);
total:=total+x;
i:=i+1
end;
mean:=total/n;
writeln;
writeln ('Total : ',total);
writeln ('Jumlah data : ',n);
writeln ('Rata-rata : ',mean:3:2);
writeln;
writeln;
writeln;
readln;
end.
=========================================================================
Semoga bermanfaat, senang berbagi :D
Tidak ada komentar:
Posting Komentar