![]() |
|
|
#1
|
|||
|
|||
|
надо что бы матрица выводила
Код:
1 2 .. n
....................
(n-2) (n-1) n
(n-1) n n
procedure TForm8.Button1Click(Sender: TObject);
var i,k,j,n,t:byte;
s: string;
begin
StringGrid1.Visible:=True;
n:=StrToInt(edit1.Text);
StringGrid1.ColCount:=n;
StringGrid1.RowCount:=n;
begin
for j:=0 to n-1 do
StringGrid1.Cells[j,0]:=inttostr(j+1); { 1 линия }
end;
begin
for i:=0 to n do
for j:=0 to n-1 do
if i+j > n then
begin
StringGrid1.Cells[i,j]:=inttostr(n);
end
else
StringGrid1.Cells[j,i]:=inttostr(i+j-1);
end;
end;у меня выводит фигню. Исправите ,пожалуйста ошибку Последний раз редактировалось Admin, 18.11.2014 в 19:14. |
|
#2
|
|||
|
|||
|
Вот так:
Код:
var
i, j, v : integer;
begin
for i = 1 to n do // rows
for j = 1 to n do // cols
begin
v := IfThen(i + j > n,n,i+j-1);
StringGrid1.Calls[j,i] := IntToStr(v);
end;
end;пример вывода (сделан на java, но арифметика та же (n=5): Код:
1 2 3 4 5 2 3 4 5 5 3 4 5 5 5 4 5 5 5 5 5 5 5 5 5 |