Program MatrixMultiplier(Input,Output);
{Written by Jason J Schwarz in Turbo Pascal v6.0.
Purpose : This program will multiply two square matrices together.}

USES CRT;
CONST
     Size = 3;
TYPE
    Matrix1 = ARRAY [1..Size,1..Size] OF REAL;
VAR
    Number1 : Matrix1;
    Number2 : Matrix1;
    Answer : Matrix1;

PROCEDURE GetNumbers;
VAR
   Row, Column : INTEGER;
BEGIN
    CLRSCR;
    GOTOXY(32,1);
    WRITELN(Output,'Matrix Multiplier');
    {$I-}
    FOR Row:=1 TO Size DO BEGIN
        FOR Column:=1 TO Size DO BEGIN
            REPEAT
                  WRITELN(Output,'Enter the ',Column,',',Row,' number of the first matrix: ');
                  READLN(Input,Number1[Column,Row]);
            UNTIL IOResult=0;
        END;{Column:=1 TO Size}
    END;{Row:=1 TO Size}
    FOR Row:=1 TO Size DO BEGIN
        FOR Column:=1 TO Size DO BEGIN
            REPEAT
                  WRITELN(Output,'Enter the ',Column,',',Row,' number of the second matrix:');
                  READLN(Input,Number2[Column,Row]);
            UNTIL IOResult=0;
        END;{Column:=1 TO Size}
    END;{Row:=1 TO Size}
    {$I+}
END;{GetNumbers}

PROCEDURE MultiplyMatrix;
VAR
    Count, Column, Row : INTEGER;
    Total : REAL;
BEGIN
    FOR Row:=1 TO Size DO BEGIN
        FOR Column:=1 TO Size DO BEGIN
            Total:=0;
            FOR Count:=1 TO Size DO BEGIN
                 Total:=(Number1[Count,Row]*Number2[Column,Count])+Total;
            END;{Count:=1 TO Size}
            Answer[Column,Row]:=Total;
        END;{Column:=1 TO Size}
    END;{Row:=1 TO Size}
END;{MultiplyMatrix}

Procedure Display;
VAR Row, Column: INTEGER;
BEGIN
     CLRSCR;
     WRITELN(Output);
     GOTOXY(21,1);
     WRITELN(Output,'Matrix Mulitplier by Jason John Schwarz');
     FOR Row:=1 TO Size DO BEGIN
         FOR Column:=1 TO Size DO BEGIN
             GOTOXY((80 DIV Size)*(Column-1)+1,(23 DIV Size)*(Row-1)+2);
             WRITE(Output,Answer[Column,Row]:6:6);
         END;{Column:=1 TO Size}
     END;{Row:=1 TO Size}
     GOTOXY(29,24);
     WRITE(Output,'Press <RETURN> to exit');
     READLN(Input);
END;{Display}

BEGIN{MatrixMultiplier}
GetNumbers;
MultiplyMatrix;
Display;
END.{MatrixMultiplier}
