Sabtu, 17 Desember 2011

Perkalian Matriks


program perkalian_matriks;
uses wincrt;
var a,b,c: array[1..10,1..10] of integer;
i,j,k1,k2,b1,b2,sum,r:integer;
begin
write('Masukkan baris Matrik A = ');readln(b1);
write('Masukkan kolom Matrik A = ');readln(k1);
write('Masukkan baris Matrik B = ');readln(b2);
write('Masukkan kolom Matrik B = ');readln(k2);
write('Masukkan Bilangan Matrik A = ');
writeln;
for i:=1 to b1 do
for j:=1 to k1 do
readln(a[i,j]);
writeln;
write('Masukkan Bilangan matrik B = ');
writeln;
for i:=1 to b2 do
for j:=1 to k2 do
readln(b[i,j]);
writeln;
writeln('Matrik A');
writeln('==================');
for i:=1 to b1 do
begin
for j:=1 to k1 do
write(a[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik B');
writeln('===================');
for i:=1 to b2 do
begin
for j:=1 to k2 do
write(b[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik A*B');
writeln('================');
for i:=1 to b1 do
begin
for j:=1 to k2 do
begin
sum:=0;
for r:=1 to k1 do
sum:=sum+a[i,r]*b[r,j];
c[i,j]:=sum;
write(c[i,j]:2,' ');
end;
writeln;
end;
end.

0 komentar:

Posting Komentar