unit Unit1;

interface

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

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

var
 Form1: TForm1;
 n,m,i,j,k:integer;
 a:mas;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  N:=4;
  m:=3;
      Edit1.Text:=FloatToStr(N);
      Edit2.Text:=FloatToStr(m);
   StringGrid1.RowCount:=N+1;
   StringGrid1.ColCount:=m+1;
   StringGrid1.Cells[0,0]:='Массив A:';
   for i:=1 to N do begin
    StringGrid1.Cells[0,i]:=' i= '+IntToStr(i);
   for j:=1 to m do
    StringGrid1.Cells[j,0]:=' j= '+IntToStr(j);
                    end;
randomize;
For i := 1 to n do
  for j := 1 to m do
   begin
    k:=random(100);
    a[i,j]:=k;
    stringgrid1.cells[j,i]:=inttostr(k);
   end
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
      n:=strtoint(Edit1.Text);
      m:=strtoint(Edit2.Text);
   StringGrid1.RowCount:=N+1;
   StringGrid1.ColCount:=m+1;
   StringGrid1.Cells[0,0]:='Массив A:';
   for i:=1 to N do begin
    StringGrid1.Cells[0,i]:=' i= '+IntToStr(i);
   for j:=1 to m do
    StringGrid1.Cells[j,0]:=' j= '+IntToStr(j);
                    end;
randomize;
For i := 1 to n do
  for j := 1 to m do
   begin
    k:=random(100);
    a[i,j]:=k;
    stringgrid1.cells[j,i]:=inttostr(k);
   end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
For i := 1 to n do
  for j := 1 to m do
   begin
    a[i,j]:=strtoint(stringgrid1.cells[j,i]);
   end;
   i:=1;
while i<n do
  begin
   for j:=1 to m do
   begin
     k:=a[i,j];
     a[i,j]:=a[i+1,j];
     a[i+1,j]:=k;
   end;
      i:=i+2;
  end;
 StringGrid2.RowCount:=N+1;
   StringGrid2.ColCount:=m+1;
StringGrid2.Cells[0,0]:='Массив B:';
   for i:=1 to N do begin
    StringGrid2.Cells[0,i]:=' i= '+IntToStr(i);
   for j:=1 to m do
    StringGrid2.Cells[j,0]:=' j= '+IntToStr(j);
                    end;
For i := 1 to n do
  for j := 1 to m do
   begin
    stringgrid2.cells[j,i]:=inttostr(a[i,j]);
   end

end;

end.
