1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Math;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
Nmax=10;
Type
Mas1 = array[1..Nmax] of Integer;
Mas2 = array[1..Nmax, 1..Nmax] of Integer; // Объявление типа двумерного массива
var
Form1: TForm1;
a,b :Mas2; // Объявление двумерного массива
N,i,j,s,M: integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
N := StrToInt(Edit1.Text);
// Задание числа строк и столбцов в таблицах
StringGrid1.ColCount := N + 1;
StringGrid1.RowCount := N + 1;
StringGrid2.RowCount := N + 1;
StringGrid2.ColCount := N + 1;
// Заполнение верхнего и левого столбцов поясняющими подписями
for i:=1 to N do
begin
StringGrid1.Cells[0, i] := 'i=' + IntToStr(i);
StringGrid1.Cells[i, 0] := 'j=' + IntToStr(i);
StringGrid2.Cells[0, i] := 'i=' + IntToStr(i);
StringGrid2.Cells[i, 0] := 'j=' + IntToStr(i);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
N := 3; // Размерность массива
Edit1.Text := FloatToStr(N);
// Задание числа строк и столбцов
StringGrid1.ColCount := N + 1;
StringGrid1.RowCount := N + 1;
StringGrid2.RowCount := N + 1;
StringGrid2.ColCount := N + 1;
// Ввод в левую верхнюю ячейку таблицы названия массива
StringGrid1.Cells[0, 0] := 'Массив A';
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);
StringGrid2.Cells[0, i] := 'i='+ IntToStr(i);
StringGrid2.Cells[i, 0] := 'j='+ IntToStr(i);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//Сортировка строк
for j:=0 to N-1 do
for i:=0 to N-j-1 do
if a[i, N] > a[i+1, N] then
begin
s := a[i, N];
a[i, N] := a[i+1, N];
a[i+1, N] := s;
end;
end;
end. |