//声明:
type TMat=array of array of real;
procedure MatricMulti(var A,B,C:TMat;m,n:integer);
//实现
procedure MatricMulti(var A,B,C:TMat;m,n:integer);
var
i,j,k:integer;
t:real;
begin
for i:=0 to m-1 do for j:=0 to m-1 do
begin
t:=0;
for k:=0 to n-1 do t:=t+A[i,k]*B[k,j];
c[i,j]:=t;
end;
end;
//调用
procedure TForm1.Button3Click(Sender: TObject);
var
x,y,z:TMat;
m,n,i,j:integer;
s:string;
begin
setlength(x,2,3);
setlength(y,3,2);
setlength(z,2,2);
m:=2;
n:=3;
for i:=0 to m-1 do for j:=0 to n-1 do
begin
x[i,j]:=i+1;
y[j,i]:=j+1;
end;
MatricMulti(x,y,z,m,n);
s:='Matrix Z:';
for i:=0 to m-1 do
begin
s:=s+#13#10;
for j:=0 to m-1 do
begin
s:=s+format(' %5.0f',[z[i,j]]);
end;
end;
showmessage(s);
//A: 1 1 1 b: 1 1 c: 6 6
// 2 2 2 2 2 12 12
// 3 3
end;