Kali ini saya memakai matriks 3 x 3...

program hitung_matriks

kamus

type Mat1= array [1..3,1..3] of integer
type Mat2= array [1..3,1..3] of integer
M1: Mat1
M2: Mat2
i,j: integer

procedure input1 (isi1: Mat1)
kamus
algoritma
i traversal [1..3]
j traversal [1..3]
input(isi1[i,j])

procedure input2 (isi2: Mat2)
kamus
algoritma
i traversal [1..3]
j traversal [1..3]
input(isi2[i,j])

procedure output1 (isi1: Mat1)
kamus
algoritma
output('Matriks 1 = ')
i traversal [1..3]
j traversal [1..3]
output(isi1[i,j],' ')

procedure output2 (isi2: Mat2)
kamus
algoritma
output('Matriks 1 = ')
i traversal [1..3]
j traversal [1..3]
output(isi2[i,j],' ')

procedure tambah(isi1: Mat1 isi2: Mat2)
kamus
algoritma
output('Hasil penjumlahan matriks tersebut= ')
i traversal [1..3]
j traversal [1..3]
output(isi1[i,j] + isi2[i,j],' ')

procedure kurang(isi1: Mat1 isi2: Mat2)
kamus
algoritma
output('Hasil pengurangan matriks tersebut= ')
i traversal [1..3]
j traversal [1..3]
output(isi1[i,j] - isi2[i,j],' ')

procedure kali(isi1: Mat1 isi2: Mat2)
kamus
algoritma
output('Hasil perkalian matriks tersebut= ')
i traversal [1..3]
j traversal [1..3]
if (i=1) and (j=1) then
output(isi1[1,1]*isi2[1,1] + isi1[1,2]*isi2[2,1] + isi1[1,3]*isi2[3,1],' ')

else if (i=1) and (j=2) then
output(isi1[1,1]*isi2[1,2] + isi1[1,2]*isi2[2,2] + isi1[1,3]*isi2[3,2],' ')

else if (i=1) and (j=3) then
output(isi1[1,1]*isi2[1,3] + isi1[1,2]*isi2[2,3] + isi1[1,3]*isi2[3,3],' ')

else if (i=2) and (j=1) then
output(isi1[2,1]*isi2[1,1] + isi1[2,2]*isi2[2,1] + isi1[2,3]*isi2[3,1],' ')

else if (i=2) and (j=2) then
output(isi1[2,1]*isi2[1,2] + isi1[2,2]*isi2[2,2] + isi1[2,3]*isi2[3,2],' ')

else if (i=2) and (j=3) then
output(isi1[2,1]*isi2[1,3] + isi1[2,2]*isi2[2,3] + isi1[2,3]*isi2[3,3],' ')

else if (i=3) and (j=1) then
output(isi1[3,1]*isi2[1,1] + isi1[3,2]*isi2[2,1] + isi1[3,3]*isi2[3,1],' ')

else if (i=3) and (j=2) then
output(isi1[3,1]*isi2[1,2] + isi1[3,2]*isi2[2,2] + isi1[3,3]*isi2[3,2],' ')

else if (i=3) and (j=3) then
output(isi1[3,1]*isi2[1,3] + isi1[3,2]*isi2[2,3] + isi1[3,3]*isi2[3,3],' ')

algoritma
input1(M1)
input2(M2)
output1(M1)
output2(M2)
tambah(M1,M2)
kurang(M1,M2)
kali(M1,M2)

0 Comments:

Post a Comment