Спираль из центра массива по часовой стрелке (для нечетных n):
const n=7;
var a:array[1..n,1..n] of integer;
i,j,d,k,l,m:integer;
begin
k:=n*n;
i:=n div 2 + 1; j:=n div 2 + 1;
a[i,j]:=k;
d:=1;
for m:=1 to n div 2 do
begin
for l:=1 to d do
begin k:=k-1; j:=j+1; a[i,j]:=k; end;
for l:=1 to d do
begin k:=k-1; i:=i+1; a[i,j]:=k; end;
d:=d+1;
for l:=1 to d do
begin k:=k-1; j:=j-1; a[i,j]:=k; end;
for l:=1 to d do
begin k:=k-1; i:=i-1; a[i,j]:=k; end;
d:=d+1;
end;
d:=d-1;
for l:=1 to d do
begin k:=k-1; j:=j+1; a[i,j]:=k; end;
for i:=1 to n do
begin
for j:=1 to n do write(a[i,j]:4);
writeln;
end;
end.
Результат:
7 6 5 4 3 2 1
8 29 28 27 26 25 24
9 30 43 42 41 40 23
10 31 44 49 48 39 22
11 32 45 46 47 38 21
12 33 34 35 36 37 20
13 14 15 16 17 18 19