TYPE
Matrix=Array[1..100,1..100] of Real;
VAR
A,B,C:Matrix;
MA,MB,MC,NA,NB,NC:Byte;
i,j,k:Byte;
Flag:Boolean;
Sum:Real;
Procedure Prod(m1,m2:Matrix; Mm1,Nm1,Mm2,Nm2:Byte;
var m3:Matrix; var Mm3:Byte; var Nm3:Byte; var Pb:boolean);
Var
q,p,r:Byte;
begin
If Nm1=Mm2 then Pb:=true else Pb:=false;
If Pb then
begin
For q:=1 to Mm1 do
For p:=1 to Nm2 do
begin
m3[q,p]:=0;
For r:=1 to Nm1 do
m3[q,p]:=m3[q,p]+m1[q,r]*m2[r,p];
end;
Mm3:=Mm1;
Nm3:=Nm2;
end;
end;
BEGIN
Write('Number of rows of matrix A = ');
Readln(MA);
Write('Number of columns of matrix A = ');
Readln(NA);
For i:=1 to MA do
For j:=1 to NA do
begin
Write('A[',i,',',j,']= ');
Readln(A[i,j]);
end;
Writeln;
Write('Number of rows of matrix B = ');
Readln(MB);
Write('Number of columns of matrix B = ');
Readln(NB);
For i:=1 to MB do
For j:=1 to NB do
begin
Write('B[',i,',',j,']= ');
Readln(B[i,j]);
end;
Writeln;
Prod(A,B,MA,NA,MB,NB,C,MC,NC,Flag);
If Flag then
begin
Writeln('Matrix A:');
For i:=1 to MA do
begin
For j:=1 to NA do
write(A[i,j]:8:1);
Writeln;
end;
Writeln;
Writeln('Matrix B:');
For i:=1 to MB do
begin
For j:=1 to NB do
write(B[i,j]:8:1);
Writeln;
end;
Writeln;
Writeln('Matrix C:');
For i:=1 to MC do
begin
For j:=1 to NC do
write(C[i,j]:8:2);
Writeln;
end;
Writeln;
Sum:=0;
For i:=1 to MC do
For j:=1 to NC do
If C[i,j]<0 then Sum:=Sum+C[i,j];
Writeln('Sum of C negatives is ',Sum:0:2);
end
else
Writeln('The number of columns of A is NOT equal to the number of rows of B!!!');
Readln;
END.