PROGRAM
pola2;
VAR
n,a,b,c :
integer
;
BEGIN
readln(n);
FOR
a:=
1
TO
n
DO
begin
for
b:=
1
TO
a
DO
begin
if
c =
10
then
c:=
0
;
write
(c);
c := c+
1
;
end
;
writeln
;
end
;
end
.
PROGRAM
pola2;
VAR
n,a,b,c :
integer
;
BEGIN
readln(n);
FOR
a:=
1
TO
n
DO
begin
for
b:=
1
TO
a
DO
begin
if
c =
10
then
c:=
0
;
write
(c);
c := c+
1
;
end
;
writeln
;
end
;
end
.
program
pola1;
var
N,i,j,k :
integer
;
begin
read(N);
for
i:=
1
to
N
do
begin
for
j:=
1
to
N-i
do
write
(
' '
);
for
k:=
1
to
i
do
write
(
'*'
);
writeln
;
end
;
readln;
readln
end
.
program
pangkatdua;
var
m,n:
longint
;
begin
read(N);
m:=
1
;
while
m<n
do
m:=m*
2
;
if
m=n
then
writeln
(
'TRUE'
)
else
writeln
(
'FALSE'
);
readln; readln
end
.
program
Breakcontinue;
var
n:
integer
;
i:
integer
;
begin
readln(n);
for
i :=
1
to
n
do
begin
if
(i =
93
)
then
begin
writeln
(
'ERROR'
);
break;
end
;
if
(i
mod
10
=
0
)
then
continue;
writeln
(i);
end
;
end
.
program
forfor;
var
jml,jbil,i,bil :
integer
;
begin
jml :=
0
;
read(jbil);
for
i :=
1
to
jbil
do
begin
read(bil);
jml := jml + bil;
end
;
writeln
(jml);
readln
end
.
var
jumlah,bil :
longint
;
begin
jumlah :=
0
;
while
not
eof(input)
do
begin
readln(bil);
jumlah := jumlah + bil;
end
;
writeln
(jumlah);
readln
end
.
Solusi BAB 1C : Perulangan - While
var
kalimat :
string
;
begin
while
not
eof(input)
do
begin
readln(kalimat);
writeln
(kalimat);
end
;
readln
end
.
program
ifthen;
var
N :
integer
;
begin
read(N);
if
N>
0
then
writeln
(N);
readln
end
.
program
ifthen;
var
N :
integer
;
begin
read(N);
if
(N>
0
)
and
(N
mod
2
=
0
)
then
writeln
(N);
readln
end
.
program
ifthen;
var
N :
integer
;
begin
read(N);
if
(N>
0
)
then
writeln
(
'positif'
)
else
begin
if
N=
0
then
writeln
(
'nol'
)
else
writeln
(
'negatif'
);
end
;
readln
end
.
Solusi BAB 1B : Percabangan - Case
var
N,bil :
longint
;
begin
read(N);
bil:=N;
case
bil
of
1..9
:
begin
writeln
(
'satuan'
);
end
;
10..99
:
begin
writeln
(
'puluhan'
);
end
;
100..999
:
begin
writeln
(
'ratusan'
);
end
;
1000..9999
:
begin
writeln
(
'ribuan'
);
end
;
10000..99999
:
begin
writeln
(
'puluhribuan'
);
end
;
end
;
readln
end
.
program
jarakmanahattan;
var
bx,by,kx,ky,x1,x2,y1,y2 :
longint
;
begin
read(x1,y1,x2,y2);
if
x1>x2
then
begin
bx:=x1;kx:=x2;
end
else
begin
bx:=x2;kx:=x1;
end
;
if
y1>y2
then
begin
by:=y1;ky:=y2;
end
else
begin
by:=y2;ky:=y1;
end
;
writeln
((bx-kx)+(by-ky));
readln
end
.
program xyz; var N:real; c,f:longint; a,b:longint; begin readln(N); if (N=trunc(N)) then begin N:=trunc(N); writeln(N:0:0,' ',N:0:0); end else if (N<0) then begin c:=trunc(N); f:=c-1; writeln(f,' ',c); end else begin f:=trunc(N); c:=f+1; writeln(f,' ',c); end; readln ;readln end.
program
hitung;
var
A,B :
integer
;
op,sp :
char
;
begin
readln(A,sp,op,sp,B);
case
op
of
'*'
:
writeln
(A*B);
'+'
:
writeln
(A+B);
'-'
:
writeln
(A-B);
'<'
:
begin
if
A>B
then
writeln
(
'salah'
)
else
writeln
(
'benar'
);
end
;
'>'
:
begin
if
A>B
then
writeln
(
'benar'
)
else
writeln
(
'salah'
);
end
;
'='
:
begin
if
A=B
then
writeln
(
'benar'
)
else
writeln
(
'salah'
);
end
;
end
;
readln
end
.
program
pertamaku;
var
pesan :
string
;
begin
read(pesan);
writeln
(pesan);
readln
end
.
program
a_tambah_b;
var
A,B :
integer
;
begin
read(A,B);
writeln
(A+B);
readln
end
.
program
bebekteman;
var
N,M :
integer
;
begin
read(N,M);
writeln
(
'masing-masing '
,N
div
M);
writeln
(
'bersisa '
,N
mod
M);
end
.
program
segi3;
var
A,T :
integer
;
luas:
real
;
begin
read(A,T);
luas:=A*T/
2
;
writeln
(luas:
0
:
2
);
readln
end
.
Solusi BAB 1A : Masukan dan Keluaran - Transpos Matriks
program
matriks;
var
a,b,c,d,e,f,g,h,i :
integer
;
begin
readln(a,b,c);
readln(d,e,f);
readln(g,h,i);
writeln
(a,
' '
,d,
' '
,g);
writeln
(b,
' '
,e,
' '
,h);
writeln
(c,
' '
,f,
' '
,i);
readln
end
.