program MatrixMultiplication;
const
RowsA = 2; // Number of rows in Matrix A
ColsA = 3; // Number of columns in Matrix A
RowsB = 3; // Number of rows in Matrix B
ColsB = 2; // Number of columns in Matrix B
type
Matrix = array of array of Integer;
var
A, B, Result: Matrix;
i, j, k: Integer;
begin
// Initialize Matrix A
SetLength(A, RowsA, ColsA);
A[0][0] := 4; A[0][1] := 2; A[0][2] := 4;
A[1][0] := 8; A[1][1] := 3; A[1][2] := 1;
// Initialize Matrix B
SetLength(B, RowsB, ColsB);
B[0][0] := 3; B[0][1] := 5;
B[1][0] := 2; B[1][1] := 8;
B[2][0] := 7; B[2][1] := 9;
// Initialize Result Matrix
SetLength(Result, RowsA, ColsB);
// Perform Matrix Multiplication
for i := 0 to RowsA - 1 do
for j := 0 to ColsB - 1 do
begin
Result[i][j] := 0;
for k := 0 to ColsA - 1 do
Result[i][j] := Result[i][j] + A[i][k] * B[k][j];
end;
// Display Result Matrix
WriteLn('Result Matrix:');
for i := 0 to RowsA - 1 do
begin
for j := 0 to ColsB - 1 do
Write(Result[i][j]:4);
WriteLn;
end;
end.
(*
run:
Result Matrix:
44 72
37 73
*)