这个是有技巧的!!!!!!!!!!!!!!
procedure TForm1.Button1Click(Sender: TObject);
var
n,i,j,nV,nH:integer;
AN:array[0..50,0..50] of integer;
s:string;
begin
n:=5;
//任意的奇数都可以 3,5,7,9,11,13,15,17,...
nH:=n div 2;
nV:=0;
for i:=1 to n*ndo
begin
an[nh,nv]:=i;
if (i mod n)=0 then
begin
nv:=(nv+1 mod n)
end
else
begin
dec(nh);
if nh=-1 then
nh:=n-1;
dec(nv);
if nv=-1 then
nv:=n-1;
end;
end;
s:='';
for i:=0 to n-1do
begin
for j:=0 to n-1do
begin
s:=s+format('%4d',[an[i,j]]);
end;
s:=s+#13#10;
end;
showmessage(s);
end;
n=3
6 7 2
1 5 9
8 3 4
n=5
15 16 22 3 9
8 14 20 21 2
1 7 13 19 25
24 5 6 12 18
17 23 4 10 11
n=7
28 29 37 45 4 12 20
19 27 35 36 44 3 11
10 18 26 34 42 43 2
1 9 17 25 33 41 49
48 7 8 16 24 32 40
39 47 6 14 15 23 31
30 38 46 5 13 21 22
n=13
91 92 106 120 134 148 162 7 21 35 49 63 77
76 90 104 105 119 133 147 161 6 20 34 48 62
61 75 89 103 117 118 132 146 160 5 19 33 47
46 60 74 88 102 116 130 131 145 159 4 18 32
31 45 59 73 87 101 115 129 143 144 158 3 17
16 30 44 58 72 86 100 114 128 142 156 157 2
1 15 29 43 57 71 85 99 113 127 141 155 169
168 13 14 28 42 56 70 84 98 112 126 140 154
153 167 12 26 27 41 55 69 83 97 111 125 139
138 152 166 11 25 39 40 54 68 82 96 110 124
123 137 151 165 10 24 38 52 53 67 81 95 109
108 122 136 150 164 9 23 37 51 65 66 80 94
93 107 121 135 149 163 8 22 36 50 64 78 79