Program berikut merupakan program Turbo Basic untuk melakukan perkalian dua buah matriks, dimana matriks tersebut memiliki ordo yang dapat ditentukan ketika program dijalankan
Cls
input “Baris Matriks A =”;m
input “Kolom Matriks A dan Baris Matriks B =”;n
input “Kolom Matriks B =”;p
Dim a(m, n)
Dim b(n, p)
Dim c(m, p)
‘Inputkan matriks A
Cls
Print “Matriks A”
For i = 1 To m
For j = 1 To n
print “Nilai Matriks A(“;i;”,”;j;”)”:input a(i,j)
Next j
Next i
‘Inputkan Matriks B
Print
Print “Matriks B”
For i = 1 To n
For j = 1 To p
print “Nilai Matriks B(“;i;”,”;j;”)”:input b(i,j)
Next j
Next i
‘Tampilkan semua Matriks
Cls
Print “Matriks A”
For i = 1 To m
For j = 1 To n
Print a(i, j),
Next j
Print
Next i
Print “Matriks B”
For i = 1 To n
For j = 1 To p
Print b(i, j),
Next j
Print
Next i
‘hitung dan tampilkan matriks C
Print
Print
Print “MATRIKS C:”
For i = 1 To m
For j = 1 To p
c(i, j) = 0
For k = 1 To n
c(i, j) = c(i, j) + a(i, k) * b(k, j)
Next k
Print c(i, j),
Next j
Print
Next i
Tidak ada komentar:
Posting Komentar