unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
const
n =
3
;
type
TMas =
array
[
1..
n,
1..
n]
of
integer
;
TForm1 =
class
(TForm)
Label1: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button1: TButton;
procedure
Button1Click(Sender: TObject);
private
public
end
;
function
MultiMatrix(A, B: TMas; d:
integer
): TMas;
var
Form1: TForm1;
implementation
{$R *.dfm}
function
MultiMatrix(A, B: TMas; d:
integer
): TMas;
var
i, j, k, sum:
integer
;
newA: TMas;
begin
if
d <>
1
then
begin
for
i :=
1
to
n
do
for
j :=
1
to
n
do
begin
sum :=
0
;
for
k :=
1
to
n
do
sum := sum + A[i,k]*B[k,j];
newA[i,j] := sum;
end
;
dec(d);
MultiMatrix(A, newA, d)
end
else
MultiMatrix := B;
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
A, B: TMas;
i, j, d:
integer
;
begin
d:=
6
;
for
i :=
1
to
n
do
for
j :=
1
to
n
do
A[i, j] := StrToInt(StringGrid1
.
Cells[i-
1
, j-
1
]);
B := MultiMatrix(A, A, d);
for
i :=
1
to
n
do
for
j :=
1
to
n
do
StringGrid2
.
Cells[i-
1
, j-
1
] := IntToStr(B[i,j]);
end
;
end
.