Das Unterprogramm zur Matrizenaddition soll in ein Hauptprogramm folgenden Ablaufs eingebettet werden :
Type Dimension = (Zeile,Spalte); Matrix = Array [1..10,1..10] Of Integer; Var Dims : Array[1..3,Dimension] Of Word; Mats : Array[1..3] Of Matrix; Function ReadKey:Char; Assembler; Asm mov ah,8 int 21h End; Function IntRead:Integer; Var Result:Integer; Signed:Boolean; Digit:Char; First:Boolean; Begin Result := 0; Signed := False; First := True; Repeat Digit := ReadKey; If (Digit='-') And First Then Begin Signed := True; First := False; Write(Digit) End; If (Digit>='0') And (Digit<='9') Then Begin First := False; Result := Result*10+(Ord(Digit)-Ord('0')); Write(Digit) End Until Digit=#13; If Signed Then Result := -1*Result; IntRead := Result End; Procedure MatRead(DimX,DimY:Word;Var Mat:Matrix); Var X,Y:Integer; Begin For Y := 1 to DimY Do For X := 1 To DimX Do Begin Write('[',Y,',',X,'] = '); Mat[X,Y] := IntRead; WriteLn End End; Procedure MatWrite(DimX,DimY:Word; Var Mat:Matrix); Var X,Y:Integer; Begin For Y := 1 To DimY Do Begin For X := 1 to DimX Do Write(Mat[X,Y]:8); WriteLn End End; Function MatMult(DimAx,DimAy,DimBx,DimBy:Word; Var DimCx,DimCy:Word; Var MatA,MatB,MatC:Matrix):Boolean; Var I,X,Y:Word; Skalar:Integer; Begin If DimAx = DimBy Then Begin MatMult := True; DimCx := DimBx; DimCy := DimAy; For X := 1 To DimCx Do For Y := 1 To DimCy Do Begin Skalar := 0; For I := 1 To DimAx Do Skalar := Skalar+MatA[I,Y]*MatB[X,I]; MatC[X,Y] := Skalar End End Else MatMult := False End; Begin WriteLn('MATRIZENMULTIPLIKATION'); Repeat Write('Zeilenanzahl 1.Matrix : '); Dims[1,Zeile] := IntRead; WriteLn Until Dims[1,Zeile] In [1..10]; Repeat Write('Spaltenanzahl 1.Matrix & Zeilenanzahl 2.Matrix : '); Dims[1,Spalte] := IntRead; Dims[2,Zeile] := Dims[1,Spalte]; WriteLn Until Dims[1,Spalte] In [1..10]; Repeat Write('Spaltenanzahl 2. Matrix : '); Dims[2,Spalte] := IntRead; WriteLn Until Dims[2,Spalte] In [1..10]; WriteLn('1.Matrix :'); MatRead(Dims[1,Spalte],Dims[1,Zeile],Mats[1]); WriteLn('2.Matrix :'); MatRead(Dims[2,Spalte],Dims[2,Zeile],Mats[2]); If MatMult(Dims[1,Spalte],Dims[1,Zeile], Dims[2,Spalte],Dims[2,Zeile], Dims[3,Spalte],Dims[3,Zeile], Mats[1],Mats[2],Mats[3]) Then Begin WriteLn('Ergebnismatrix :'); MatWrite(Dims[3,Spalte],Dims[3,Zeile],Mats[3]) End Else WriteLn('Unexpected Severe Error') End.