有点意思
以下是代码
procedure TForm1.Button1Click(Sender: TObject);
var a: array[1..10,1..10] of integer;
i,j,n: integer;
begin
Col,EndCol,begin
Row,EndRow: integer;
s: string;
begin
n := 1;
begin
Row := 1;
EndRow := 10;
begin
Col := 1;
EndCol := 10;
while (begin
Row <= EndRow) or (begin
Col <= EndCol)do
begin
for i := begin
Col to EndColdo
begin
a[begin
Row,i] := n;
n := n + 1;
end;
begin
Row := begin
Row + 1;
for i := begin
Row to EndRowdo
begin
a[i,EndCol] := n;
n := n + 1;
end;
EndCol := EndCol - 1;
for i := EndColdo
wnto begin
Coldo
begin
a[EndRow,i] := n;
n := n + 1;
end;
EndRow := EndRow - 1;
for i := EndRowdo
wnto begin
Rowdo
begin
a[i,begin
Col] := n;
n := n + 1;
end;
begin
Col := begin
Col + 1;
end;
for i := 1 to 10do
begin
s := '';
for j := 1 to 10do
s := s + Format('%3d',[a[i,j]]) + ' ';
Memo1.Lines.Append(s);
end;
end;
运行结果
1 2 3 4 5 6 7 8 9 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19