program magic;
var
i,j,k,n,x,y,m:longint;
a:array[1..100,1..100] of longint;
procedure print;
begin
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j],‘ ‘);
writeln;
end;
end;
begin
readln(n);
for i:=1 to n do
for j:=1 to n do
begin
inc(k);
a[i,j]:=k;
end;
i:=1;m:=n;
repeat
x:=a[i,i];a[i,i]:=a[m,m];a[m,m]:=x;
y:=a[i,m];a[i,m]:=a[m,i];a[m,i]:=y;
inc(i);dec(m);
until i>n div 2;
print;
end.
原文:http://www.cnblogs.com/gaoshanxun/p/4954911.html