begin // заполнение for j:=1 to n do if j mod 2=0 then for i:=n downto 1 do a[i,j]:=j*n-i+1 else for i:=1 to n do a[i,j]:=n*(j-1)+i; // вывод for i:=1 to n do begin for j:=1 to n do Write(a[i,j]:3); Writeln end end.
Pascal // var A: array [1..4, 1..4] of byte; i, j: byte; begin for i := 1 to 4 do for j := 1 to 4 do begin if (i mod 2 = 1) then A[j, i] := (i - 1) * 4 + j else A[j, i] := i * 4 - j + 1; end; //A[2,4] := 16; for i := 1 to 4 do begin for j := 1 to 4 do write(A[i, j]:4); writeln; end; end.
const
n=4;
var
a:array[1..n,1..n] of integer;
i,j:integer;
begin
// заполнение
for j:=1 to n do
if j mod 2=0 then
for i:=n downto 1 do a[i,j]:=j*n-i+1
else
for i:=1 to n do a[i,j]:=n*(j-1)+i;
// вывод
for i:=1 to n do begin
for j:=1 to n do Write(a[i,j]:3);
Writeln
end
end.
Результат
1 8 9 16
2 7 10 15
3 6 11 14
4 5 12 13
Замечание: значение n можно менять.
Pascal
//
var
A: array [1..4, 1..4] of byte;
i, j: byte;
begin
for i := 1 to 4 do
for j := 1 to 4 do
begin
if (i mod 2 = 1) then
A[j, i] := (i - 1) * 4 + j
else
A[j, i] := i * 4 - j + 1;
end;
//A[2,4] := 16;
for i := 1 to 4 do
begin
for j := 1 to 4 do
write(A[i, j]:4);
writeln;
end;
end.
//
Пример:
1 8 9 16
2 7 10 15
3 6 11 14
4 5 12 13