Квадратная матрица порядка n по заданному образцу
| Код | 1 2 3 ... n-2 n-1 n 2 3 4 ... n-1 n 0 3 4 5 ... n 0 0 . . n-1 n 0... 0 2 0 n 0 0... 0 0 1 |
т.е. для n=5 будет, для n=6. Диагональ с правого нижнего угла, поднимается вверх начиная с 1 до пересечения с другой диагональю. Вот.
| Код | 12345 123456 23450 234560 34500 345600 45020 456300 50001 560020 600001 |
Никак не могу понять, как с диагональю этого добиться. Заранее спасибо.
ТЕКСТ ПРОГРАММЫ
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Spin, Grids;
type TForm1 = class(TForm) Button1: TButton; StringGrid1: TStringGrid; SpinEdit1: TSpinEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var a:array of array of byte; n,i,j:byte; begin n:=Spinedit1.Value; StringGrid1.ColCount:=n; StringGrid1.RowCount:=n; Setlength(a,n,n); for i:=0 to n-1 do for j:=0 to n-1 do begin if j<=n-i-1 then a[i,j]:=i+j+1 else a[i,j]:=0; StringGrid1.Cells[j,i]:=Inttostr(a[i,j]);
end; end;
end. |
|