unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Edit2: TEdit;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  const
  Nmax=10;
  Mmax=10;
  type
  Mas2=array[1..Nmax,1..Mmax] of extended;

var
  Form1: TForm1;
  A,B:Mas2;
  N,M,i,k,j:integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
N:=3;
Edit1.Text:=FloatToStr(N);
StringGrid1.RowCount:=N+1;
StringGrid2.RowCount:=N+1;
M:=4;
Edit2.Text:=FloatToStr(M);
StringGrid1.ColCount:=M+1;

StringGrid1.Cells[0,0]:='Массив А:';
StringGrid2.Cells[0,0]:='Массив B:';
for i:=1 to N do begin
StringGrid1.Cells[0,i]:='i='+IntToStr(i);
StringGrid1.Cells[i,0]:='j='+IntToStr(i);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
M:=StrToInt(Edit2.Text);
StringGrid1.ColCount:=M+1;

N:=StrToInt(Edit1.Text);
StringGrid1.RowCount:=N+1;
StringGrid2.RowCount:=N+1;
for i:=1 to N do begin
StringGrid1.Cells[0,i]:='i='+IntToStr(i);
StringGrid1.Cells[i,0]:='j='+IntToStr(i);
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
s:extended;
l: Extended;
i,j,k: Integer;
b:array[1..Nmax,1..Mmax] of extended;
begin
for j:=1 to m do
    for k:=1 to n-1 do
      for i:=1 to (n-1) do
      A[i,j]:=StrToFloat(StringGrid1.Cells[i,j]);
        begin
          if a[i,j]>a[i+1,j] then  // сортировка: если правый элемент меньше левого то меняем местами
            begin
            B[i,j]:=a[i,j];
            a[i,j]:=a[i+1,j];
              a[i+1,j]:=B[i,j];
              StringGrid2.Cells[i,j] := FloatToStrF(B[i,j], ffFixed, 0, 6)
            end;
        end;
        end;

end.
