Delphi 生成 杨辉三角(采用动态生成二维数组,其中将数组第一行,第二行直接写入,之后的数组成员依据他们生成)
var
a:array of array of integer;
i,j:integer;
temp_Str:string;
line:integer;
begin
line:=strtoint(edit1.Text);
//#13#10换行符
myMemo.Lines.Text:='';
SetLength(a,line,line);
for i := 0 to line-1 do
begin
if i=0 then
begin
a[i][0]:=1;
continue ;
end;
if i=1 then
begin
a[i][0]:=1;
a[i][1]:=1;
continue;
end;
for j := 0 to i do
begin
if j=0 then
begin
a[i][j]:=1;continue;
end;
if j=i then
begin
a[i][j]:=1;continue;
end;
a[i][j]:=a[i-1][j-1]+a[i-1][j];
end;
end;
for i := 0 to line-1 do
begin
temp_Str:='';
for j := 0 to i do
temp_Str:=temp_Str+inttostr(a[i][j])+' ';
myMemo.Lines.add(temp_Str);
end;
end;
浙公网安备 33010602011771号