主题:螺旋方阵谁能看懂
var j:integer;
n,i,k,x,y:byte;
r:array[1..25,1..25]of byte;
begin
write('n=');readln(n);
for x:=1 to n do
for y:=1 to n do r[x,y]:=0;
x:=0;y:=n;i:=0;k:=n;j:=1;
while i<n*n do
begin
for i:=i+1 to i+k do
begin
x:=x+j;
r[x,y]:=i;
end;
dec(k);
if j=1 then j:=-1 else j:=1;
for i:=i+1 to i+k do
begin
y:=y+j;
r[x,y]:=i;
end;
end;
for x:=1 to n do
begin
for y:=1 to n do write(r[x,y]:3);
writeln;
end;
end.
n,i,k,x,y:byte;
r:array[1..25,1..25]of byte;
begin
write('n=');readln(n);
for x:=1 to n do
for y:=1 to n do r[x,y]:=0;
x:=0;y:=n;i:=0;k:=n;j:=1;
while i<n*n do
begin
for i:=i+1 to i+k do
begin
x:=x+j;
r[x,y]:=i;
end;
dec(k);
if j=1 then j:=-1 else j:=1;
for i:=i+1 to i+k do
begin
y:=y+j;
r[x,y]:=i;
end;
end;
for x:=1 to n do
begin
for y:=1 to n do write(r[x,y]:3);
writeln;
end;
end.