06.12.2023, 12:41
|
Прохожий
|
|
Регистрация: 28.11.2023
Сообщения: 3
Версия Delphi: delphi 11
Репутация: 10
|
|
Массив в стрингриде
нужно заполнить массив нулями как на картинке у меня получилось только треугольником на искосок а надо как конвертиком вот код
помогите пожалуйста
Код:
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: пользуемся тегами для оформления
|