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
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
.