unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button2: TButton;
    Button3: TButton;
    StringGrid2: TStringGrid;
    Label3: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 const
 Nmax=10;
 Mmax=10;

 Type
 Mas2=array[1..Nmax,1..Mmax] of extended;
 Mas1=array[1..1,1..Mmax] of extended;

var
  Form1: TForm1;
  a: Mas2;
  b: Mas1;
  k,i,j,n,m,f: integer;
  max: extended;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
{$R+}
k:=1;

while k<n do begin
max:=a[k,1];
for i:=1 to n-k+1 do
 for j:=1 to m do
 if max<a[i,j] then  begin
  max:=a[i,j];
  f:=i;
 end;

for j:=1 to m do begin
 b[1,j]:=a[f,j]  ;
 a[f,j]:=a[n-k+1,j]   ;
 a[n-k+1,j]:=b[1,j]    ;
end;

k:=k+1;
end;

for i:=1 to n do
 for j:=1 to m do   begin
  StringGrid2.RowCount:=n+1 ;
  StringGrid2.ColCount:=m+1 ;
  StringGrid2.Cells[j,i]:=FloatToStr(a[i,j]);
 end;
end;



procedure TForm1.Button3Click(Sender: TObject);
begin
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
StringGrid1.RowCount:=n+1 ;
StringGrid1.ColCount:=m+1 ;
Randomize;
for i:=1 to n do
 for j:=1 to m do begin
   a[i,j]:=random(41);
   StringGrid1.Cells[j,i]:=FloatToStr(a[i,j]);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
n:=3;
m:=3;
Edit1.Text:=FloatToStr(n);
Edit2.Text:=FloatToStr(m) ;
StringGrid1.RowCount:=n+1 ;
StringGrid1.ColCount:=m+1 ;
StringGrid1.Cells[0,0]:='Массив 1' ;
StringGrid2.RowCount:=n+1 ;
StringGrid2.ColCount:=m+1 ;
StringGrid2.Cells[0,0]:='Массив 2' ;
for i:=1 to n do begin
  StringGrid1.Cells[0,i]:='i='+IntToStr(i);
  StringGrid1.Cells[i,0]:='j='+IntToStr(i);
  end;
for i:=1 to n do begin
  StringGrid2.Cells[0,i]:='i='+IntToStr(i);
  StringGrid2.Cells[i,0]:='j='+IntToStr(i);
  end;

end;

end.
