Contoh Program Perkalian Rantai Matrix dengan Pascal:


program perkalian_rantai_matrix;
uses crt;

var
i,j,k,x,y,z:integer;
a,b,c : array [1..50,1..50] of integer;

begin
clrscr;
writeln('Ukuran matrix A');
write('Jumlah Baris: ');
readln(x);
write('Jumlah Kolom: ');
readln(y);
writeln;
writeln('Ukuran matrix B');
writeln('Jumlah Baris : ',y);
write('Jumlah Kolom : ');
readln(z);

for i:=1 to x do
for j:=1 to y do
begin
write('Nilai A[',i,',',j,'] : ');
readln(a[i,j]);
end;

writeln;
for i:=1 to y do
for j:=1 to z do
begin
write('Nilai B[',i,',',j,'] : ');
readln(b[i,j]);
end;

for i:=1 to x do
for j:=1 to z do
for k:=1 to y do
c[i,j] := c[i,j] + a[i,k]*b[k,j];
writeln;
writeln;
writeln('Berikut Adalah Hasil perkalian Matrix A dan Matrix B: ');
Writeln;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j],' ');
writeln;
end;

writeln;
readln;

end.

No comments