Показать сообщение отдельно
  #1  
Старый 06.12.2023, 12:41
Kartem Kartem вне форума
Прохожий
 
Регистрация: 28.11.2023
Сообщения: 3
Версия Delphi: delphi 11
Репутация: 10
По умолчанию Массив в стрингриде


нужно заполнить массив нулями как на картинке у меня получилось только треугольником на искосок а надо как конвертиком вот код
помогите пожалуйста

Код:
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
unit Unit1;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Button3: TButton;
    StringGrid3: TStringGrid;
 
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
const cou = 5;
var
  Form1: TForm1;
  table: array[1..cou, 1..cou] of integer;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
var i,j: integer;
  begin
    randomize;
    for i := 1 to cou do
    for j := 1 to cou do
    begin
      table[i,j]:=random(100);
    end;
    with stringgrid1 do
    begin
      colcount:= cou + 1;
     rowcount := cou + 1;
      for i := 1  to cou do
      for j := 1 to cou do
      begin
        Cells[i,j] := inttostr(table[i,j]);
      end;
    end;
  end;
 
end;
procedure TForm1.Button2Click(Sender: TObject);
 
  var i,j,p,b,a:integer;
 
begin
 
for a := 1 to cou do    {сортировка методом пузырька всего массива}
  begin
   {сортировка методом пузырька только по столбцам}
   for p := 1 to cou do
   for i:=1 to cou do
    for j:=1 to cou-1 do
    if table[i,j] > table[i,j+1] then
     begin  {Обмен элементов}
      b:=table[i,j];
      table[i,j]:=table[i,j+1];
      table[i,j+1]:=b;
     end;
 
  {сортировка методом пузырька только по строкам}
   for p := 1 to cou do
   for i:=1 to cou-1 do
    for j:=1 to cou do
    if table[i,j] > table[i+1,j] then
     begin  {Обмен элементов}
      b:=table[i,j];
      table[i,j]:=table[i+1,j];
      table[i+1,j]:=b;
     end;
  end;
  with stringgrid2 do
  begin
     colcount:= cou + 1;
     rowcount := cou + 1;
     for i := 1 to cou do
       for j := 1 to cou do
         begin
           cells[i,j]:= inttostr(table[i,j]);
         end;
  end;
end;
 
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
begin
for i := 1 to cou do
  for j := 1 to cou do
  if ( j>=i ) then table[i,j]:=0;
  with stringgrid3 do
  begin
     colcount:= cou + 1;
     rowcount := cou + 1;
     for i := 1 to cou do
       for j := 1 to cou do
         begin
           cells[i,j]:= inttostr(table[i,j]);
         end;
  end;
end;
 
end.

lmikle: пользуемся тегами для оформления
Ответить с цитированием