var
num:array of integer;
....
procedure Tform1.zhSum(n, m: integer);
var
a: array of integer;
i, j,sum: integer;
r: longword;
hm: string;
begin
i := 0;
r := 0;
SetLength(a,n);
a := 1;
while truedo
begin
if (a - i <= n - m + 1) then
begin
if (i = m - 1) then
begin
inc(r);
hm := IntToStr(r) + ':';
sum:=0;
for j := 0 to m - 1do
if j < m - 1 then
sum := sum + Num[a[j]-1]
else
sum := sum + Num[a[j]-1];
RichEdit1.Lines.Add(IntToStr(sum));
a := a + 1;
continue;
end;
inc(i);
a := a[i - 1] + 1;
end
else
begin
if (i = 0) then
exit;
dec(i);
a := a + 1;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,sum:integer;
begin
SetLength(Num,SpinEdit1.value);
for i:=0 to SpinEdit1.value-1do
Num:=i+2;
//对数组赋值
for i:=2 to SpinEdit1.valuedo
zhSum(SpinEdit1.value,i);
end;