PROGRAM MatrixMul(Input, Output);
    { Program 6.3 - Matrix Multiplication }
    CONST
        M = 4;
        P = 3;
        N = 2;
    VAR
        I: 1..M;
        J: 1..N;
        K: 1..P;
        Sum, Element: Integer;
        A: Array [1..M, 1..P] OF Integer;
        B: Array [1..P, 1..N] OF Integer;
        C: Array [1..M, 1..N] OF Integer;
BEGIN
    { Assign initial values to A }
    FOR I := 1 TO M DO BEGIN
        FOR K := 1 TO P DO BEGIN
            Read(Input, Element);
            Write(Output, Element);
            A[I, K] := Element;
        END;
        WriteLn(Output)
    END;
    WriteLn(Output);

    { Assign initial values to B }
    FOR K := 1 TO P DO BEGIN
        FOR J := 1 TO N DO BEGIN
            Read(Input, Element);
            Write(Output, Element);
            B[K, J] := Element;
        END;
        WriteLn(Output)
    END;
    WriteLn(Output);

    { Nultiply A and B to get C }
    FOR I := 1 TO M DO BEGIN
        FOR J := 1 TO N DO BEGIN
            Sum := 0;
            FOR K := 1 TO P DO
                Sum := Sum + A[I, k] * B[K, J];
            C[I, J] := Sum;
            Write(Output, Sum)
        END;
        WriteLn(Output)
    END;
    WriteLn(Output);
End.



