{ Multiplikation von Matrizen             }
{ Autor: Dipl.-Ing. Thomas Speiser        }
{ Source from: http://Codes.TurboTools.de }

program matrizen_multi;
uses Crt;
const m = 3;
      n = 4;
      p = 2;

var  m1:  array[1..n,1..m] of integer;
     m2:  array[1..p,1..n] of integer;
     m3:  array[1..p,1..m] of integer;

procedure Mat_Multi;
var i,j,k: integer;
begin
for i:=1 to m do
 for k:=1 to p do
  for j:=1 to n do
   m3[k,i]:=m1[j,i] * m2[k,j] + m3[k,i];
end;

var x,y: integer;

begin
ClrScr;
m1[1,1]:=2; m1[2,1]:=2; m1[3,1]:=1; m1[4,1]:=3;
m1[1,2]:=1; m1[2,2]:=3; m1[3,2]:=2; m1[4,2]:=5;
m1[1,3]:=2; m1[2,3]:=2; m1[3,3]:=4; m1[4,3]:=1;

m2[1,1]:=1; m2[2,1]:=3;
m2[1,2]:=2; m2[2,2]:=2;
m2[1,3]:=5; m2[2,3]:=4;
m2[1,4]:=4; m2[2,4]:=5;

writeLN('  MATRIX1: ');

for x:=1 to n do
 for y:=1 to m do
 begin
  gotoxy(3*x,y+1);
  write(m1[x,y]);
 end;

writeLN;
writeLN;
writeLN('  MATRIX2: ');

for x:=1 to p do
 for y:=1 to n do
 begin
  gotoxy(3*x,y+6);
  write(m2[x,y]);
 end;

mat_multi;

writeLN;
writeLN;
writeLN('  MATRIX3 = MATRIX1 * MATRIX2');

for x:=1 to p do
 for y:=1 to m do
 begin
  gotoxy(3*x,y+12);
  write(m3[x,y]);
 end;

readLN;
end.