参照楼上的思路function n3ToSum(n:Cardinal):string;var n2,index,nm:Cardinal
a:array of Cardinal
s:string
i:integer;begin result:=''
if n=0 then exit
SetLength(a,n)
n2:=n*n
try if n mod 2<>0 then begin index:=(n-1) div 2
a[index]:=n2
end else begin index:=n div 2-1
n2:=n2-1
a[index]:=n2
end
nm:=n2-2
for i:=index-1 downto 0 do begin a:=nm
dec(nm,2)
end
nm:=n2+2
for i:=index+1 to n-1 do begin a:=nm
inc(nm,2)
end
for n2:=n-1 downto 0 do s:=inttostr(a[n2])+'+'+s
finally SetLength(a,0)
end
Delete(s,length(s),1)
result:=s;end;procedure TForm1.Button1Click(Sender: TObject);begin edit2.Text:=n3ToSum(StrToInt(edit1.Text));end;