Const n=5;
var a:array[1..n,1..n] of integer;
i,j,d,k,l,m:integer;
begin
k:=1;
i:=1; j:=1;
a[i,j]:=1;
d:=n-1;
for l:=1 to d do
begin k:=k+1; j:=j+1; a[i,j]:=k; end;
for m:=1 to n div 2 do
begin
for l:=1 to d do
begin k:=k+1; i:=i+1; a[i,j]:=k; end;
for l:=1 to d do
begin k:=k+1; j:=j-1; a[i,j]:=k; end;
d:=d-1;
for l:=1 to d do
begin k:=k+1; i:=i-1; a[i,j]:=k; end;
for l:=1 to d do
begin k:=k+1; j:=j+1; a[i,j]:=k; end;
d:=d-1;
end;
for i:=1 to n do
begin
for j:=1 to n do write(a[i,j]:4);
writeln;
end;
end.
Результат:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9