Write a program to find the multiplication of two matrices using pointers.Input formatInput consists of (n*m)+(p*q)+4 integer inputs.First line of the input consists of two integers 'n' and 'm', which are thedimensions of the matrix 1,Followed by two integers 'p' and 'q', which are the dimensions of the matrix 2,Followed by the elements of matrix 1,Followed by the elements of matrix 2.
Here is a Pascal program to find the multiplication of two matrices using pointers:
program MatrixMultiplication;
type
TMatrix = array of array of Integer;
TMatrixPointer = ^TMatrix;
var
n, m, p, q, i, j, k: Integer;
matrix1, matrix2, result: TMatrix;
ptr1, ptr2, ptrRes: TMatrixPointer;
begin
readln(n, m, p, q);
if m <> p then
begin
writeln('Matrix multiplication not possible with given dimensions.');
exit;
end;
SetLength(matrix1, n, m);
SetLength(matrix2, p, q);
SetLength(result, n, q);
ptr1 := @matrix1;
ptr2 := @matrix2;
ptrRes := @result;
for i := 0 to n - 1 do
for j := 0 to m - 1 do
read(ptr1^[i][j]);
for i := 0 to p - 1 do
for j := 0 to q - 1 do
read(ptr2^[i][j]);
for i := 0 to n - 1 do
for j := 0 to q - 1 do
for k := 0 to m - 1 do
ptrRes^[i][j] := ptrRes^[i][j] (ptr1^[i][k] * ptr2^[k][j]);
writeln('Resultant Matrix:');
for i := 0 to n - 1 do
begin
for j := 0 to q - 1 do
write(ptrRes^[i][j], ' ');
writeln;
end;
end.
ExpertInStudy.com is a smart community of thousands of students and experts. It is thanks to them that even the most difficult questions get quick and good answers. Here you can become an expert and start making money!