01 Program
Perkalian_Matriks;
02 | uses wincrt; |
03 | var |
04 | a,f,k: array [ 1..10 , 1..10 ] of integer ; |
05 | b,c,i,j,l,z: longint ; m,n,d,e,g,h: byte ; |
06 | begin clrscr; |
07 | {write(' Program Perkalian 2 Matriks');readln;writeln;} |
08 | writeln ( 'Masukkan data untuk matriks pertama (M1)' ); |
09 | write ( 'banyaknya baris matriks pertama: ' ); readln(b); |
10 | write ( 'banyaknya kolom matriks pertama: ' ); readln(c); |
11 | for d:= 1 to b do |
12 | begin |
13 | for e:= 1 to c do |
14 | begin |
15 | write ( 'entri baris ke-' ,d, ' kolom ke-' ,e, ': ' ); readln(a[d,e]); |
16 | end ; |
17 | end ; |
18 | for d:= 1 to b do |
19 | begin |
20 | for e:= 1 to c do |
21 | begin |
22 | write (a[d,e]: 7 ); |
23 | end ; writeln ; |
24 | end ; writeln ; |
25 | writeln ( 'Masukkan data untuk matriks kedua (M2)' ); |
26 | write ( 'berapa banyak baris matriks kedua? ' ); readln(g); |
27 | write ( 'berapa banyak kolom matriks kedua? ' ); readln(h); |
28 | for i:= 1 to g do |
29 | begin |
30 | for j:= 1 to h do |
31 | begin |
32 | write ( 'entri baris ke-' ,i, ' kolom ke ' ,j, ': ' ); readln(f[i,j]); |
33 | end ; |
34 | end ; |
35 | for i:= 1 to g do |
36 | begin |
37 | for j:= 1 to h do |
38 | begin |
39 | write (f[i,j]: 7 ); |
40 | end ; writeln ; |
41 | end ; writeln ; |
42 | if c=i then begin |
43 | writeln ( 'M1 x M2:' ); writeln ; |
44 | for d:= 1 to b do |
45 | begin |
46 | for l:= 1 to h do |
47 | begin |
48 | for e:= 1 to c do |
49 | begin |
50 | for j:= l to h do |
51 | begin |
52 | for i:=e to g do |
53 | begin |
54 | k[d,j]:=k[d,j]+a[d,e]*f[i,j]; |
55 | if c=e then |
56 | begin |
57 | write (k[d,j]: 7 ); |
58 | end ; |
59 | i:=g; |
60 | end ; |
61 | j:=h; |
62 | end ; |
63 | end ; |
64 | end ; |
65 | writeln ; |
66 | end ; |
67 | end else |
68 | begin |
69 | writeln ( 'Maaf?! Operasi dari M1 x M2 tidak dapat dilakukan' ); |
70 | writeln ( 'karena kolom M1 (' ,c, ' kolom) tidak sama dengan baris M2 (' ,i, ' baris)' ); |
71 | end ; |
72 | readln end . |