1. Program bagi pemula dengan struktur biasa
Program Contoh_Awal;
Uses CRT;
Var i,j,k : integer;
Begin
ClrScr;
Write(‘masukkan nilai i dan j : ‘);
Readln(i,j);
k:=i+j;
Writeln(‘nilai k : ‘,k);
Readln;
End.
Uses CRT;
Var i,j,k : integer;
Begin
ClrScr;
Write(‘masukkan nilai i dan j : ‘);
Readln(i,j);
k:=i+j;
Writeln(‘nilai k : ‘,k);
Readln;
End.
2. Program bagi pemula dengan struktur biasa
Program ContohInteger;
Uses CRT;
Var y : Integer;
p : Real;
X : Real;
Begin
y := 5;
p := 6;
x := y + p;
Writeln(‘Nilai X adalah :’,x:4:1);
End.
Program ContohInteger;
Uses CRT;
Var y : Integer;
p : Real;
X : Real;
Begin
y := 5;
p := 6;
x := y + p;
Writeln(‘Nilai X adalah :’,x:4:1);
End.
3. Program untuk menginput sejumlah variabel dan menampilkannya
Program Contoh_Variabel;
Uses crt;
Var
Nama : string[15];
Jumlah,harga : Longint;
Nilai : real;
Begin
ClrScr;
{Memasukkan data}
Nama:=’Semen';
jumlah:=10;
harga :=250000;
Nilai :=Harga * Jumlah ;
{Menampilkan Data yang Telah Diproses}
writeln(‘Nama Barang:’,Nama);
writeln(‘Jumlah:’,Jumlah);
writeln(‘Harga:’,Harga);
writeln(‘Nilai Barang:’,Nilai);
Readln;
end.
Uses crt;
Var
Nama : string[15];
Jumlah,harga : Longint;
Nilai : real;
Begin
ClrScr;
{Memasukkan data}
Nama:=’Semen';
jumlah:=10;
harga :=250000;
Nilai :=Harga * Jumlah ;
{Menampilkan Data yang Telah Diproses}
writeln(‘Nama Barang:’,Nama);
writeln(‘Jumlah:’,Jumlah);
writeln(‘Harga:’,Harga);
writeln(‘Nilai Barang:’,Nilai);
Readln;
end.
4. Program untuk mengolah variabel
(* Variable dan Konstanta *)
Program Contoh_2a;
Uses CRT;
Const phi = 3.14;
Var x : Integer;
y : Real;
Begin
ClrScr;
x := 5;
y := x * phi;
Writeln(‘Nilai y = ‘, y:5:2);
Readln;
End.
Program Contoh_2a;
Uses CRT;
Const phi = 3.14;
Var x : Integer;
y : Real;
Begin
ClrScr;
x := 5;
y := x * phi;
Writeln(‘Nilai y = ‘, y:5:2);
Readln;
End.
5. Program untuk mengolah variabel, konstanta dengan model lain
Program Contoh_2b;
Uses CRT;
Const phi = 3.14;
Var x : Integer;
y : Real;
Begin
ClrScr;
Write(‘Masukkan Harga x =’);
Readln(x);
y := x * phi;
Writeln(‘Nilai y = ‘, y:10:2);
Readln;
End.
Uses CRT;
Const phi = 3.14;
Var x : Integer;
y : Real;
Begin
ClrScr;
Write(‘Masukkan Harga x =’);
Readln(x);
y := x * phi;
Writeln(‘Nilai y = ‘, y:10:2);
Readln;
End.
6. Program untuk mengolah data dengan type
{ Deklarasi Type }
Program Contoh_3a;
Uses CRT;
Type bulat = Integer;
pecahan = Real;
var x : bulat;
y : pecahan;
Begin
clrscr;
Write(‘Harga x : ‘); Readln(x);
Write(‘Harga y : ‘); Readln(y);
Writeln(‘Nilai x : ‘,x:3);
Writeln(‘Harga y : ‘,y:3:0);
Readln;
End.
Program Contoh_3a;
Uses CRT;
Type bulat = Integer;
pecahan = Real;
var x : bulat;
y : pecahan;
Begin
clrscr;
Write(‘Harga x : ‘); Readln(x);
Write(‘Harga y : ‘); Readln(y);
Writeln(‘Nilai x : ‘,x:3);
Writeln(‘Harga y : ‘,y:3:0);
Readln;
End.
7. Program untuk mengolah data dengan type
{ Deklarasi Type }
Program Contoh_3b;
Uses CRT;
Type bulat = Integer;
pecahan = Real;
var x : bulat;
y : pecahan;
Label Ulang;
Begin
Ulang:
clrscr;
Write(‘Harga x : ‘); Readln(x);
Write(‘Harga y : ‘); Readln(y);
Writeln(‘Nilai x : ‘,x:3);
Writeln(‘Harga y : ‘,y:3:0);
readln;
Goto Ulang;
End.
Program Contoh_3b;
Uses CRT;
Type bulat = Integer;
pecahan = Real;
var x : bulat;
y : pecahan;
Label Ulang;
Begin
Ulang:
clrscr;
Write(‘Harga x : ‘); Readln(x);
Write(‘Harga y : ‘); Readln(y);
Writeln(‘Nilai x : ‘,x:3);
Writeln(‘Harga y : ‘,y:3:0);
readln;
Goto Ulang;
End.
8. Program membandingkan 2 variabel
Program Banding;
Uses CRT;
Var a, b : Integer;
Uses CRT;
Var a, b : Integer;
Begin
ClrScr;
read(a);
read(b);
if (a >b) then
Writeln(‘Bilangan A terbesar’)
else
Writeln(‘Bilangan B terbesar’);
end.
ClrScr;
read(a);
read(b);
if (a >b) then
Writeln(‘Bilangan A terbesar’)
else
Writeln(‘Bilangan B terbesar’);
end.
9. Program membandingkan 3 variabel
Program BanVar2;
Uses CRT;
Var a, b, c : Integer;
Uses CRT;
Var a, b, c : Integer;
Begin
write(‘Masukkan bilangan A :’); readln(A);
write(‘Masukkan bilangan B :’); readln(B);
write(‘Masukkan bilangan C :’); readln(C);
write(‘Masukkan bilangan A :’); readln(A);
write(‘Masukkan bilangan B :’); readln(B);
write(‘Masukkan bilangan C :’); readln(C);
if (a>b) then
if (a>c) then
Writeln(‘Bilangan A terbesar’)
else
Writeln(‘Bilangan C terbesar’)
else
if (b>c) then
Writeln(‘Bilangan B terbesar’)
else
Writeln(‘Bilangan C terbesar’);
End.
if (a>c) then
Writeln(‘Bilangan A terbesar’)
else
Writeln(‘Bilangan C terbesar’)
else
if (b>c) then
Writeln(‘Bilangan B terbesar’)
else
Writeln(‘Bilangan C terbesar’);
End.
10. Program membandingkan 3 variabel model lain
Program BanVar2;
Uses CRT;
Var a, b, c : Integer;
Uses CRT;
Var a, b, c : Integer;
Begin
write(‘Masukkan bilangan A :’); readln(A);
write(‘Masukkan bilangan B :’); readln(B);
write(‘Masukkan bilangan C :’); readln(C);
write(‘Masukkan bilangan A :’); readln(A);
write(‘Masukkan bilangan B :’); readln(B);
write(‘Masukkan bilangan C :’); readln(C);
if (a>b) then
if (a>c) then
begin
Writeln(‘Bilangan A terbesar’);
if (b>c) then
Writeln(‘Bilangan C terkecil’)
else
Writeln(‘Bilangan B terkecil’);
End
else
begin
Writeln(‘Bilangan C terbesar’);
Writeln(‘Bilangan B terkecil’);
end
else
if (b>c) then
begin
Writeln(‘Bilangan B terbesar’);
if (a>c) then
Writeln(‘Bilangan C terkecil’)
else
Writeln(‘Bilangan A terkecil’);
end
else
begin
Writeln(‘Bilangan C terbesar’);
Writeln(‘Bilangan A terkecil’);
end;
End.
if (a>c) then
begin
Writeln(‘Bilangan A terbesar’);
if (b>c) then
Writeln(‘Bilangan C terkecil’)
else
Writeln(‘Bilangan B terkecil’);
End
else
begin
Writeln(‘Bilangan C terbesar’);
Writeln(‘Bilangan B terkecil’);
end
else
if (b>c) then
begin
Writeln(‘Bilangan B terbesar’);
if (a>c) then
Writeln(‘Bilangan C terkecil’)
else
Writeln(‘Bilangan A terkecil’);
end
else
begin
Writeln(‘Bilangan C terbesar’);
Writeln(‘Bilangan A terkecil’);
end;
End.
11. Program membandingkan 3 variabel model lain
Program Bandingkan3Variabel;
Uses CRT;
Var a,b,c : Real;
jb : Char;
Begin
jb := ‘y';
Repeat
ClrScr;
Write(‘A = ‘); Readln(a);
Write(‘B = ‘); Readln(b);
Write(‘C = ‘); Readln(c);
If (a > b) Then
If (a > c) Then
Begin
Writeln(‘Bil. A terbesar’);
if (b c) Then
Begin
Writeln(‘Bil. B terbesar’);
if (a <= c) Then
Writeln(‘Bil. A terkecil’)
Else
Writeln(‘C Terkecil’)
End
Else
Begin
Writeln(‘Bil. C terbesar’);
Writeln(‘Bil. A terkecil’)
End;
Write(‘Ulangi (y/t) : ‘); Readln(jb);
Until jb=’t';
End.
Uses CRT;
Var a,b,c : Real;
jb : Char;
Begin
jb := ‘y';
Repeat
ClrScr;
Write(‘A = ‘); Readln(a);
Write(‘B = ‘); Readln(b);
Write(‘C = ‘); Readln(c);
If (a > b) Then
If (a > c) Then
Begin
Writeln(‘Bil. A terbesar’);
if (b c) Then
Begin
Writeln(‘Bil. B terbesar’);
if (a <= c) Then
Writeln(‘Bil. A terkecil’)
Else
Writeln(‘C Terkecil’)
End
Else
Begin
Writeln(‘Bil. C terbesar’);
Writeln(‘Bil. A terkecil’)
End;
Write(‘Ulangi (y/t) : ‘); Readln(jb);
Until jb=’t';
End.
12. Program untuk Tipe data Boolean
Program Boolean1;
Uses CRT;
var tokka : boolean;
lahir : String;
nama : String;
jawab : char;
Uses CRT;
var tokka : boolean;
lahir : String;
nama : String;
jawab : char;
Begin
Write(‘Masukkan nama : ‘);
readln (nama);
Write(‘Pernahkah melahirkan ?(Y/T) : ‘);
readln(jawab);
Write(‘Masukkan nama : ‘);
readln (nama);
Write(‘Pernahkah melahirkan ?(Y/T) : ‘);
readln(jawab);
if (jawab =’Y’) or (jawab=’y’) then tokka := true
else tokka := false;
else tokka := false;
if (tokka= False) then
Writeln(‘Berarti anda pria’)
else
Writeln(‘Berarti anda wanita’)
End.
Writeln(‘Berarti anda pria’)
else
Writeln(‘Berarti anda wanita’)
End.
13. Program untuk membedakan bilangan ganjil dan genap
Program ContohGanjilGenap;
Uses CRT;
var i : Byte;
ganjil, genap : Byte;
Begin
Clrscr;
ganjil := 0;
genap := 0;
For i:= 1 to 100 do
Begin
if (i mod 2)=0 Then
Inc(genap)
Else
Inc (ganjil);
End;
Writeln(‘Jumlah bilangan genap : ‘,genap);
Writeln(‘Jumlah bilangan ganjil : ‘,ganjil);
Readln;
End.
Uses CRT;
var i : Byte;
ganjil, genap : Byte;
Begin
Clrscr;
ganjil := 0;
genap := 0;
For i:= 1 to 100 do
Begin
if (i mod 2)=0 Then
Inc(genap)
Else
Inc (ganjil);
End;
Writeln(‘Jumlah bilangan genap : ‘,genap);
Writeln(‘Jumlah bilangan ganjil : ‘,ganjil);
Readln;
End.
14. Program untuk membedakan bilangan ganjil dan genap
Program gangen;
uses crt;
var
bil : integer;
jumgen, jumgan : Integer;
i : byte;
Label ulang;
uses crt;
var
bil : integer;
jumgen, jumgan : Integer;
i : byte;
Label ulang;
begin
jumgen := 0;
jumgan := 0;
i := 1;
jumgen := 0;
jumgan := 0;
i := 1;
ulang:
write(‘Masukkan bila ke-‘,i,’ : ‘); readln(bil);
if (bil mod 2 = 0) then
jumgen := jumgen+1
else
jumgan := jumgan+1;
write(‘Masukkan bila ke-‘,i,’ : ‘); readln(bil);
if (bil mod 2 = 0) then
jumgen := jumgen+1
else
jumgan := jumgan+1;
if (i<10) then
begin
inc(i);
goto ulang;
end else
Begin
Writeln(‘Jumlah bilangan genap : ‘,jumgen);
Writeln(‘Jumlah bilangan ganjil : ‘, jumgan);
halt(1);
end;
end.
begin
inc(i);
goto ulang;
end else
Begin
Writeln(‘Jumlah bilangan genap : ‘,jumgen);
Writeln(‘Jumlah bilangan ganjil : ‘, jumgan);
halt(1);
end;
end.
15. Program menggunakan label
{ Deklarasi Label }
Program Contoh_1;
Uses Crt;
Label A;
Begin
Clrscr;
a:
Writeln(‘Belajar Pascal’);
goto A;
End.
Program Contoh_1;
Uses Crt;
Label A;
Begin
Clrscr;
a:
Writeln(‘Belajar Pascal’);
goto A;
End.
16. Program untuk mengkonversi waktu
Program BagiDIV;
Uses CRT;
var jam, menit, detik : Integer;
jlhdetik : integer;
Begin
ClrScr;
Write(‘Jam : ‘); Readln(jlhdetik);
jam := jlhdetik div 3600;
menit := (jlhdetik mod 3600) div 60;
detik := (jlhdetik mod 3600) mod 60;
Writeln(‘Jam : ‘, jam);
Writeln(‘Menit : ‘, menit);
Writeln(‘Detik : ‘, detik);
Readln;
End.
Uses CRT;
var jam, menit, detik : Integer;
jlhdetik : integer;
Begin
ClrScr;
Write(‘Jam : ‘); Readln(jlhdetik);
jam := jlhdetik div 3600;
menit := (jlhdetik mod 3600) div 60;
detik := (jlhdetik mod 3600) mod 60;
Writeln(‘Jam : ‘, jam);
Writeln(‘Menit : ‘, menit);
Writeln(‘Detik : ‘, detik);
Readln;
End.
17. Program menggunakan perintah MOD
Program Modulus;
Uses CRT;
var i : Byte;
Begin
Clrscr;
for i:=1 to 10 do
Writeln(i,’ mod 3 = ‘, i mod 3);
Readln;
End.
Uses CRT;
var i : Byte;
Begin
Clrscr;
for i:=1 to 10 do
Writeln(i,’ mod 3 = ‘, i mod 3);
Readln;
End.
18. Program Password
Uses CRT;
Label 5;
var kata: string[25];
i : integer;
Begin
Clrscr;
i := 1;
Repeat
Write(‘Anda Kuliah Dimana ? :’);
Readln(kata);
if i = 3 Then
Begin
Clrscr;
Writeln(‘Bye-bye’);
Goto 5;
End
Else
i := i+1;
Until Kata=’BD';
Writeln(‘Pasword anda benar’);
5 :
End.
Label 5;
var kata: string[25];
i : integer;
Begin
Clrscr;
i := 1;
Repeat
Write(‘Anda Kuliah Dimana ? :’);
Readln(kata);
if i = 3 Then
Begin
Clrscr;
Writeln(‘Bye-bye’);
Goto 5;
End
Else
i := i+1;
Until Kata=’BD';
Writeln(‘Pasword anda benar’);
5 :
End.
19. Program yang menggunakan sejumlah perintah dengan menu pilihan
uses crt;
var
jurusan, kelas, cc : string;
pil, kls : byte;
totharga, harga : longint;
jlh : integer;
var
jurusan, kelas, cc : string;
pil, kls : byte;
totharga, harga : longint;
jlh : integer;
begin
clrscr;
writeln(‘Pilih Tujuan’);
writeln(‘————–‘);
writeln(‘1.Jakarta’);
writeln(‘2.Yogya’);
clrscr;
writeln(‘Pilih Tujuan’);
writeln(‘————–‘);
writeln(‘1.Jakarta’);
writeln(‘2.Yogya’);
writeln(‘3.Surabaya’);
writeln(‘————-‘);
write(‘Pilih jurusan : ‘); readln(pil);
writeln;
writeln(‘————-‘);
write(‘Pilih jurusan : ‘); readln(pil);
writeln;
Writeln(‘Pilih Kelas : ‘);
Writeln(‘1. Eksekutif’);
Writeln(‘2. Bisnis’);
Writeln(‘3. Ekonomi’);
writeln;
Write(‘Pilihan Anda : ‘); readln(kls);
Write(‘Jumlah tiket : ‘); readln(jlh);
Writeln(‘1. Eksekutif’);
Writeln(‘2. Bisnis’);
Writeln(‘3. Ekonomi’);
writeln;
Write(‘Pilihan Anda : ‘); readln(kls);
Write(‘Jumlah tiket : ‘); readln(jlh);
if (pil=1) then
begin
cc:=’Jakarta';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 70000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 40000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 10000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end;
end else
begin
cc:=’Jakarta';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 70000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 40000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 10000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end;
end else
if (pil =2) then
begin
cc:=’Yogyakarta';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 80000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 50000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 20000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end
end else
begin
cc:=’Yogyakarta';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 80000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 50000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 20000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end
end else
if (pil =3) then
begin
cc:=’Surabaya';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 90000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 60000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 30000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end;
end else
begin
cc := ‘Tidak jelas';
kelas := ‘Tidak jelas';
harga := 0;
totharga := harga * jlh;
end;
begin
cc:=’Surabaya';
case kls of
1 : begin
kelas := ‘Eksekutif';
harga := 90000;
totharga := harga * jlh;
end;
2 : begin
kelas := ‘Bisnis';
harga := 60000;
totharga := harga * jlh;
end;
3 : begin
kelas := ‘Ekonomi';
harga := 30000;
totharga := harga * jlh;
end;
else begin
kelas := ‘tidak jelas';
harga :=0;
totharga := harga * jlh;
end;
end;
end else
begin
cc := ‘Tidak jelas';
kelas := ‘Tidak jelas';
harga := 0;
totharga := harga * jlh;
end;
writeln;
Writeln(‘Tujuan : ‘, cc);
Writeln(‘Kelas : ‘, kelas);
Writeln(‘Harga pertiket : Rp.’,harga);
Writeln(‘Harga Total : Rp.’,totharga);
readln;
end.
Writeln(‘Tujuan : ‘, cc);
Writeln(‘Kelas : ‘, kelas);
Writeln(‘Harga pertiket : Rp.’,harga);
Writeln(‘Harga Total : Rp.’,totharga);
readln;
end.
20. Program untuk membuat menu pilhan
Program Pilihan;
Uses Crt;
Var
pil, i : byte;
Bil, JumBilGjl, JumBilGnp, BilBes, BilKec : Integer;
Jen_kel, Hobby, Sifat : String;
piljen, pilhob : byte;
Uses Crt;
Var
pil, i : byte;
Bil, JumBilGjl, JumBilGnp, BilBes, BilKec : Integer;
Jen_kel, Hobby, Sifat : String;
piljen, pilhob : byte;
Label UlangGanGen, UlangKecBes, Ulang;
Begin
Ulang :
Clrscr;
Textcolor(15);
Writeln(‘Menu Pilihan : ‘);
Writeln(‘1. Tampil semua bil ganjil dan genap sekaligus dari 10 kali input data’);
Writeln(‘2. Tampil bil yang terbesar dan terkecil sekaligus dari 10 kali input data’);
Writeln(‘3. Tampil sifat seseorang berdasarkan input data’);
Writeln(‘4. Keluar’);
Writeln;
Write(‘Masukkan pilihan Anda : ‘); Readln(pil);
Case pil of
1 : Begin
(* Menampilkan semua bilangan ganjil dan genap
sekaligus dari 10 kali input data *)
Ulang :
Clrscr;
Textcolor(15);
Writeln(‘Menu Pilihan : ‘);
Writeln(‘1. Tampil semua bil ganjil dan genap sekaligus dari 10 kali input data’);
Writeln(‘2. Tampil bil yang terbesar dan terkecil sekaligus dari 10 kali input data’);
Writeln(‘3. Tampil sifat seseorang berdasarkan input data’);
Writeln(‘4. Keluar’);
Writeln;
Write(‘Masukkan pilihan Anda : ‘); Readln(pil);
Case pil of
1 : Begin
(* Menampilkan semua bilangan ganjil dan genap
sekaligus dari 10 kali input data *)
JumBilGjl := 0; JumBilGnp := 0; i := 1;
UlangGanGen :
Write(‘Masukkan bilangan ke-‘, i , ‘ : ‘); Readln (bil);
UlangGanGen :
Write(‘Masukkan bilangan ke-‘, i , ‘ : ‘); Readln (bil);
If (bil mod 2 = 0) then
JumBilGnp := JumBilGnp + 1
Else
JumBilGjl := JumBilGjl + 1;
JumBilGnp := JumBilGnp + 1
Else
JumBilGjl := JumBilGjl + 1;
If (i BilBes) then
Begin
BilBes := bil;
If (bil < BilKec) then
BilKec := bil;
End Else
If (bil<BilKec) Then
BilKec := bil;
Begin
BilBes := bil;
If (bil < BilKec) then
BilKec := bil;
End Else
If (bil<BilKec) Then
BilKec := bil;
If (ib Then
if a>c Then
besar :=a
Else besar := c
Else If b>c Then
besar := b
Else besar := c;
Writeln(‘Bilangan a,b,c : ‘, a,’, ‘,b,’, ‘,c);
Writeln(‘Bilangan terbesar : ‘, besar);
Readln;
End.
if a>c Then
besar :=a
Else besar := c
Else If b>c Then
besar := b
Else besar := c;
Writeln(‘Bilangan a,b,c : ‘, a,’, ‘,b,’, ‘,c);
Writeln(‘Bilangan terbesar : ‘, besar);
Readln;
End.
22. Program pengolahan data
Program SoalNo2;
Uses CRT;
Var i : Byte;
Begin
ClrScr;
i:=10;
while (i >= 1) Do
Begin
If i mod 2 = 1 Then
Begin
Write(i,’ ‘);
if i= 5 Then
exit
End;
Dec(i);
End;
Readln;
End.
Uses CRT;
Var i : Byte;
Begin
ClrScr;
i:=10;
while (i >= 1) Do
Begin
If i mod 2 = 1 Then
Begin
Write(i,’ ‘);
if i= 5 Then
exit
End;
Dec(i);
End;
Readln;
End.
23. Program pengolahan data
Program SoalNo3;
Uses CRT;
var NIM : String[9];
Nm : String[25];
nh : Char;
tgs, mid, fnl, tot : Real;
Begin
ClrScr;
Write(‘NIM : ‘); Readln(NIM);
Write(‘Nama : ‘); Readln(Nm);
Write(‘Tugas : ‘); Readln(tgs);
Write(‘MID : ‘); Readln(mid);
Write(‘Final : ‘); Readln(fnl);
tot := 0.2*tgs + 0.3*Mid + 0.5*fnl;
If tot >= 80 Then nh := ‘A’ Else
If tot >= 70 Then nh := ‘B’ Else
If tot >= 51 Then nh := ‘C’ Else
If tot >= 41 Then nh := ‘D’ Else
nh := ‘E';
Clrscr;
Writeln(‘ DAFTAR NILAI MAHASISWA’);
Writeln(‘ JURUSAN INFORMATIKA’);
Writeln;
Write(‘NIM Mahasiwa : ‘,NIM);
Writeln(‘ Nama Mahasiswa : ‘,Nm);
Writeln(‘Nilai Tugas : ‘,tgs:3:2);
Writeln(‘Nilai Mid Test : ‘,mid:3:2);
Writeln(‘Nilai final Test : ‘, fnl:3:2);
Write(‘Total Nilai : ‘,tot:3:2);
Writeln(‘ Nilai Huruf : ‘,nh);
Readln;
End.
Uses CRT;
var NIM : String[9];
Nm : String[25];
nh : Char;
tgs, mid, fnl, tot : Real;
Begin
ClrScr;
Write(‘NIM : ‘); Readln(NIM);
Write(‘Nama : ‘); Readln(Nm);
Write(‘Tugas : ‘); Readln(tgs);
Write(‘MID : ‘); Readln(mid);
Write(‘Final : ‘); Readln(fnl);
tot := 0.2*tgs + 0.3*Mid + 0.5*fnl;
If tot >= 80 Then nh := ‘A’ Else
If tot >= 70 Then nh := ‘B’ Else
If tot >= 51 Then nh := ‘C’ Else
If tot >= 41 Then nh := ‘D’ Else
nh := ‘E';
Clrscr;
Writeln(‘ DAFTAR NILAI MAHASISWA’);
Writeln(‘ JURUSAN INFORMATIKA’);
Writeln;
Write(‘NIM Mahasiwa : ‘,NIM);
Writeln(‘ Nama Mahasiswa : ‘,Nm);
Writeln(‘Nilai Tugas : ‘,tgs:3:2);
Writeln(‘Nilai Mid Test : ‘,mid:3:2);
Writeln(‘Nilai final Test : ‘, fnl:3:2);
Write(‘Total Nilai : ‘,tot:3:2);
Writeln(‘ Nilai Huruf : ‘,nh);
Readln;
End.
24. Program pengolahan data
Program Sore1;
Uses CRT;
Var a,b,c,d, kecil : Integer;
Begin
ClrScr;
Write(‘Harga a : ‘); Readln(a);
Write(‘Harga b : ‘); Readln(b);
Write(‘Harga c : ‘); Readln(c);
d:= c; c := b; b := a; a := d;
if a<b Then
if a<c Then
kecil :=a
Uses CRT;
Var a,b,c,d, kecil : Integer;
Begin
ClrScr;
Write(‘Harga a : ‘); Readln(a);
Write(‘Harga b : ‘); Readln(b);
Write(‘Harga c : ‘); Readln(c);
d:= c; c := b; b := a; a := d;
if a<b Then
if a<c Then
kecil :=a
Else kecil := c
Else If b<c Then
kecil := b
Else kecil := c;
Writeln(‘Bilangan a,b,c : ‘, a,’, ‘,b,’, ‘,c);
Writeln(‘Bilangan terkecil : ‘, kecil);
Readln;
End.
Else If b<c Then
kecil := b
Else kecil := c;
Writeln(‘Bilangan a,b,c : ‘, a,’, ‘,b,’, ‘,c);
Writeln(‘Bilangan terkecil : ‘, kecil);
Readln;
End.
25. Program pengolahan data
Program Sore2;
Uses CRT;
Var i : Byte;
Begin
ClrScr;
i:=1;
while (i =3.00) then
Writeln(‘Anda berhasil lulus’)
else
Writeln(‘Anda perlu belajar lebih giat’)
Readln;
End.
Uses CRT;
Var i : Byte;
Begin
ClrScr;
i:=1;
while (i =3.00) then
Writeln(‘Anda berhasil lulus’)
else
Writeln(‘Anda perlu belajar lebih giat’)
Readln;
End.
31. Program untuk pergeseran BIT
Program BitWise;
Uses CRT;
Begin
ClrScr;
Writeln(4 shl 1);
Readln;
end.
Uses CRT;
Begin
ClrScr;
Writeln(4 shl 1);
Readln;
end.
32. Program untuk pergeseran BIT
Program BitWise;
Uses CRT;
Var x, y : Integer;
Begin
ClrScr;
Write(‘Harga x : ‘); Readln(x);
Uses CRT;
Var x, y : Integer;
Begin
ClrScr;
Write(‘Harga x : ‘); Readln(x);
Write(‘Harga y : ‘); Readln(y);
Writeln(‘x shr y = ‘,x shr y);
Writeln(‘x shl y = ‘,x shl y);
Readln;
End.
Writeln(‘x shr y = ‘,x shr y);
Writeln(‘x shl y = ‘,x shl y);
Readln;
End.
33. Program yang menggunakan tipe data WORD
Program ContohWord;
Uses CRT, Dos;
Var hh,mm,ss,ns : Word;
i: byte;
Begin
ClrScr;
Settime(0,0,0,0);
for i := 1 to 10 do
Writeln(‘i = ‘,i);
gettime(hh,mm,ss,ns);
Writeln(hh:3,mm:3,ss:3,ns:3);
Readln;
End.
Uses CRT, Dos;
Var hh,mm,ss,ns : Word;
i: byte;
Begin
ClrScr;
Settime(0,0,0,0);
for i := 1 to 10 do
Writeln(‘i = ‘,i);
gettime(hh,mm,ss,ns);
Writeln(hh:3,mm:3,ss:3,ns:3);
Readln;
End.
34. Program menggunakan Array
Program BalikArray;
Uses CRT;
Var a : array[1..25] of char;
temp : char;
i,n : byte;
Begin
Clrscr;
Writeln(‘Masukkan Nilai Array’);
for i:= 1 to 5 do
Begin
Write(‘a[‘,i,’]= ‘); Readln(a[i]);
End;
clrscr;
for i := 1 to 5 do
Write(a[i],’ ‘);
Writeln;
Uses CRT;
Var a : array[1..25] of char;
temp : char;
i,n : byte;
Begin
Clrscr;
Writeln(‘Masukkan Nilai Array’);
for i:= 1 to 5 do
Begin
Write(‘a[‘,i,’]= ‘); Readln(a[i]);
End;
clrscr;
for i := 1 to 5 do
Write(a[i],’ ‘);
Writeln;
i:=1; n:=5;
While (i<=n) do
Begin
temp := a[i];
a[i] := a[n];
a[n] := temp;
inc(i);
dec(n);
End;
for i:=1 to 5 do
Write(a[i],’ ‘);
Readln;
End.
While (i<=n) do
Begin
temp := a[i];
a[i] := a[n];
a[n] := temp;
inc(i);
dec(n);
End;
for i:=1 to 5 do
Write(a[i],’ ‘);
Readln;
End.
Latihan Array :
35. typing and then run
Program Array_1D_0;
Uses CRT;
Var
n,i : byte;
a : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘Data yang ke-‘,i, ‘ = ‘); readln(a[i]);
end;
begin
write(‘Data yang ke-‘,i, ‘ = ‘); readln(a[i]);
end;
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
writeln(‘Data yang ke-‘,i, ‘ = ‘, a[i]:4:2);
writeln(‘Data yang ke-‘,i, ‘ = ‘, a[i]:4:2);
readln;
End.
End.
36. Typing and then Run
Program Array_1D_1;
Uses CRT;
Var
n,i : byte;
a,b : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a,b : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
end;
begin
write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
end;
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
writeln(‘B[‘, i, ‘] = ‘ , b[i]:4:2);
end;
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
writeln(‘B[‘, i, ‘] = ‘ , b[i]:4:2);
end;
readln;
End.
End.
37. Typing and then Run
Program Array_1D_1_1;
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
write(‘Data C[‘,i, ‘] = ‘); readln(c[i]);
end;
begin
write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
write(‘Data C[‘,i, ‘] = ‘); readln(c[i]);
end;
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ ‘);
writeln(’C[‘, i, ‘] = ‘ , c[i]:4:2);
end;
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ ‘);
writeln(’C[‘, i, ‘] = ‘ , c[i]:4:2);
end;
readln;
End.
End.
38. Typing and then Run
Program Input_Array_1D;
Uses CRT;
Var
n,i : byte;
a,b : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a,b : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
(* membaca data dengan menentukan posisi input *)
i := 1;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
i := 1;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
writeln;
writeln(‘Data-data anda yang telah diinput sebelumnya’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
writeln(‘B[‘, i, ‘] = ‘ , b[i]:4:2);
end;
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ ‘);
writeln(‘B[‘, i, ‘] = ‘ , b[i]:4:2);
end;
readln;
End.
End.
39. Typing and then Run
Program Jumlah_Array_1D;
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
i := 1;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
(* bagian ini untuk melakukan penjumlahan Array A dan B
dan disimpan di C’ *)
for i := 1 to n do
c[i] := a[i] + b[i];
dan disimpan di C’ *)
for i := 1 to n do
c[i] := a[i] + b[i];
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Hasil penjumlahan dari data yang telah diinput sebelumnya’);
writeln;
writeln(‘Hasil penjumlahan dari data yang telah diinput sebelumnya’);
for i := 1 to 58 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ + ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ = ‘);
writeln(c[i]:5:2);
end;
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ + ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ = ‘);
writeln(c[i]:5:2);
end;
readln;
End.
End.
40. Typing and then Run
Program Kurang_Array_1D;
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
Uses CRT;
Var
n,i : byte;
a,b,c : array [1..500] of real;
Begin
clrscr;
write(‘Masukkan banyak elemen data : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data-data anda yang akan diinput melalui keyboard’);
for i := 1 to 50 do
write(chr(205));
writeln;
write(chr(205));
writeln;
i := 1;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
while (i<=n) do
begin
gotoxy(2, 4+i); write(‘Data A[‘,i, ‘] = ‘); readln(a[i]);
gotoxy(25,4+i); write(‘Data B[‘,i, ‘] = ‘); readln(b[i]);
i := i+1;
end;
(* bagian ini untuk melakukan penjumlahan Array A dan B
dan disimpan di C’ *)
for i := 1 to n do
c[i] := a[i] – b[i];
dan disimpan di C’ *)
for i := 1 to n do
c[i] := a[i] – b[i];
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Hasil pengurangan dari data yang telah diinput sebelumnya’);
writeln;
writeln(‘Hasil pengurangan dari data yang telah diinput sebelumnya’);
for i := 1 to 58 do
write(chr(205));
writeln;
write(chr(205));
writeln;
for i := 1 to n do
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ – ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ = ‘);
writeln(c[i]:5:2);
end;
begin
write(‘A[‘, i, ‘] = ‘ , a[i]:4:2, ‘ – ‘);
write(‘B[‘, i, ‘] = ‘ , b[i]:4:2, ‘ = ‘);
writeln(c[i]:5:2);
end;
readln;
End.
End.
41. Typing and then Run
Program Jumlah_Matriks_2D;
Uses CRT;
Var
n,i,j, posx : byte;
posa, posb, posc : byte;
a,b,c : array [1..10,1..10] of real;
Begin
clrscr;
writeln(‘Masukkan ukuran ordo matriks maksimum 2′);
write(‘Masukkan ukuran ordo : ‘); readln(n);
Uses CRT;
Var
n,i,j, posx : byte;
posa, posb, posc : byte;
a,b,c : array [1..10,1..10] of real;
Begin
clrscr;
writeln(‘Masukkan ukuran ordo matriks maksimum 2′);
write(‘Masukkan ukuran ordo : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data matriks yang akan diinput melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data matriks yang akan diinput melalui keyboard’);
(* untuk membuat garis *)
for i := 1 to 50 do
write(chr(205));
writeln;
for i := 1 to 50 do
write(chr(205));
writeln;
(* memasukkan Array A *)
i := 1;
while (i<=n) do
begin
posx := 2;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data A[‘,i, ‘,’ ,j, ‘] = ‘);
readln(a[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
i := 1;
while (i<=n) do
begin
posx := 2;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data A[‘,i, ‘,’ ,j, ‘] = ‘);
readln(a[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
(* memasukkan Array B *)
i := 1;
while (i<=n) do
begin
posx := 40;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data B[‘,i, ‘,’ ,j, ‘] = ‘);
readln(b[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
i := 1;
while (i<=n) do
begin
posx := 40;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data B[‘,i, ‘,’ ,j, ‘] = ‘);
readln(b[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
(* bagian ini untuk melakukan penjumlahan Array A dan B
dan disimpan di C’ *)
for i := 1 to n do
for j := 1 to n do
c[i,j] := a[i,j] + b[i,j];
dan disimpan di C’ *)
for i := 1 to n do
for j := 1 to n do
c[i,j] := a[i,j] + b[i,j];
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Hasil penjulahan dari data yang telah diinput sebelumnya’);
writeln;
writeln(‘Hasil penjulahan dari data yang telah diinput sebelumnya’);
for i := 1 to 56 do
write(chr(205));
writeln;
write(chr(205));
writeln;
i := 1;
while (i<=n) do
begin
posa := 2;
posb := 23;
posc := 47;
j := 1;
while (j<=n) do
begin
gotoxy(posa, 10+i); writeln(a[i,j]:5:0);
gotoxy(posb, 10+i); writeln(b[i,j]:5:0);
gotoxy(posc, 10+i); writeln(c[i,j]:5:0);
posa := posa + 6;
posb := posb + 6;
posc := posc + 8;
j := j+1;
end;
i := i+1;
end;
while (i<=n) do
begin
posa := 2;
posb := 23;
posc := 47;
j := 1;
while (j<=n) do
begin
gotoxy(posa, 10+i); writeln(a[i,j]:5:0);
gotoxy(posb, 10+i); writeln(b[i,j]:5:0);
gotoxy(posc, 10+i); writeln(c[i,j]:5:0);
posa := posa + 6;
posb := posb + 6;
posc := posc + 8;
j := j+1;
end;
i := i+1;
end;
readln;
End.
End.
42. Typing and then Run
Program Perkalian_Matriks_2D;
Uses CRT;
Var
n,i,j,k, posx : byte;
posa, posb, posc : byte;
a,b,c : array [1..10,1..10] of real;
Begin
clrscr;
writeln(‘Masukkan ukuran ordo matriks maksimum 2′);
write(‘Masukkan ukuran ordo : ‘); readln(n);
Uses CRT;
Var
n,i,j,k, posx : byte;
posa, posb, posc : byte;
a,b,c : array [1..10,1..10] of real;
Begin
clrscr;
writeln(‘Masukkan ukuran ordo matriks maksimum 2′);
write(‘Masukkan ukuran ordo : ‘); readln(n);
(* bagian ini untuk memasukkan elemen data array
melalui keyboard *)
writeln;
writeln(‘Data matriks yang akan diinputkan melalui keyboard’);
melalui keyboard *)
writeln;
writeln(‘Data matriks yang akan diinputkan melalui keyboard’);
(* untuk membuat garis *)
for i := 1 to 50 do
write(chr(205));
writeln;
for i := 1 to 50 do
write(chr(205));
writeln;
(* memasukkan Array A *)
i := 1;
while (i<=n) do
begin
posx := 2;
j := 1;
while (j<=n) do
i := 1;
while (i<=n) do
begin
posx := 2;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data A[‘,i, ‘,’ ,j, ‘] = ‘);
readln(a[i,j]);
gotoxy(posx, 5+i); write(‘Data A[‘,i, ‘,’ ,j, ‘] = ‘);
readln(a[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
j := j+1;
end;
i := i+1;
end;
(* memasukkan Array B *)
i := 1;
while (i<=n) do
begin
posx := 40;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data B[‘,i, ‘,’ ,j, ‘] = ‘);
readln(b[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
i := 1;
while (i<=n) do
begin
posx := 40;
j := 1;
while (j<=n) do
begin
gotoxy(posx, 5+i); write(‘Data B[‘,i, ‘,’ ,j, ‘] = ‘);
readln(b[i,j]);
posx := posx + 17;
j := j+1;
end;
i := i+1;
end;
(* bagian ini untuk melakukan perkalian Array A dan B
dan disimpan di C’ *)
for i := 1 to n do
for j := 1 to n do
begin
c[i,j] := 0;
for k :=1 to n do
c[i,j] := c[i,j] + a[i,k] * b[k,j];
end;
dan disimpan di C’ *)
for i := 1 to n do
for j := 1 to n do
begin
c[i,j] := 0;
for k :=1 to n do
c[i,j] := c[i,j] + a[i,k] * b[k,j];
end;
(* bagian ini untuk mencetak data ke layar *)
writeln;
writeln(‘Hasil penjulahan dari data yang telah diinput sebelumnya’);
writeln;
writeln(‘Hasil penjulahan dari data yang telah diinput sebelumnya’);
for i := 1 to 56 do
write(chr(205));
writeln;
write(chr(205));
writeln;
i := 1;
while (i<=n) do
begin
posa := 2;
posb := 23;
posc := 47;
j := 1;
while (j<=n) do
begin
gotoxy(posa, 10+i); writeln(a[i,j]:5:0);
gotoxy(posb, 10+i); writeln(b[i,j]:5:0);
gotoxy(posc, 10+i); writeln(c[i,j]:5:0);
posa := posa + 6;
posb := posb + 6;
posc := posc + 8;
j := j+1;
end;
i := i+1;
end;
while (i<=n) do
begin
posa := 2;
posb := 23;
posc := 47;
j := 1;
while (j<=n) do
begin
gotoxy(posa, 10+i); writeln(a[i,j]:5:0);
gotoxy(posb, 10+i); writeln(b[i,j]:5:0);
gotoxy(posc, 10+i); writeln(c[i,j]:5:0);
posa := posa + 6;
posb := posb + 6;
posc := posc + 8;
j := j+1;
end;
i := i+1;
end;
readln;
End.
End.
Tidak ada komentar:
Posting Komentar