unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
StringGrid: TStringGrid;
Button2: TButton;
Edit3: TEdit;
Edit4: TEdit;
Label3: TLabel;
Label4: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
A: array of array of integer;
m, n: integer;
imax, jmax, imin, jmin: integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
i, j: integer;
begin
if (Edit1.Text<>'') and (Edit2.Text<>'') then begin
Randomize;
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
SetLength(A,n,m);
for j:=0 to m-1 do
for i:=0 to n-1 do
begin
A[i,j]:=Round(Sin(Random(100))*100);
end;
StringGrid.RowCount:=n+1;
StringGrid.ColCount:=m+1;
with StringGrid do
begin
for i:=1 to RowCount do
begin
Cells[i,0]:=IntToStr(i);
end;
for j:=1 to ColCount do
begin
Cells[0,j]:=IntToStr(j);
end;
end;
with StringGrid do
begin
for i:=1 to n do
for j:=1 to m do
Cells[j,i]:=IntToStr(A[i-1,j-1]);
end;
end
else Showmessage('Введите размерность массива.');
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
i, j: integer;
begin
imax:=0;
jmax:=0;
imin:=0;
jmin:=0;
For i:=0 to High(A) do
For j:=0 to High(A) do
if A[i,j] > A[imax,jmax] then begin
imax:=i;
jmax:=j;
end;
For i:=0 to High(A) do
For j:=0 to High(A) do
if A[i,j] < A[imin,jmin] then begin
imin:=i;
jmin:=j;
end;
Edit3.Text:=IntToStr(A[imax,jmax])+' индексы ['+IntToStr(imax+1)+','+IntToStr(jmax+1)+']';
Edit4.Text:=IntToStr(A[imin,jmin])+' индексы ['+IntToStr(imin+1)+','+IntToStr(jmin+1)+']';
end;
procedure TForm1.Button3Click(Sender: TObject);
Var
i, j, p: integer;
begin
p:=A[imax,jmax];
A[imax,jmax]:=A[imin,jmin];
A[imin,jmin]:=p;
with StringGrid do
begin
for i:=1 to n do
for j:=1 to m do
Cells[j,i]:=IntToStr(A[i-1,j-1]);
end;
end;
end.