pascal问题 杨辉三角
发布网友
发布时间:2022-04-26 17:28
我来回答
共3个回答
热心网友
时间:2022-04-26 18:57
var
n,i,j:integer;
a:array[0..20,0..20] of integer;
begin
readln(n);
for i:=1 to n do
for j:=1 to i do
if (j=1)or(i=j) then
a[i,j]:=1
else
a[i,j]:=a[i-1,j-1]+a[i-1,j];
for i:=1 to n do
begin
for j:=1 to i do write(a[i,j],' ');
writeln;
end;
end.
热心网友
时间:2022-04-26 20:15
var
a:array[1..10,1..13]of integer;
i,j,k,s:integer;
begin
read(s);
for i:=1 to s do
begin
for j:=1 to 13 do
a[i,j]:=0;
a[i,s-(i-1)]:=1;
a[i,s+(i-1)]:=1;
for k:=1 to i-2 do
begin
j:=s-(i-1)+2*k;
a[i,j]:=a[i-1,j-1]+a[i-1,j+1];
end;
for j:=1 to 13 do
if a[i,j]<>0 then
if 2*i+10=j then begin
write(a[i,j]);break;
end
else
write(a[i,j],' ');
writeln;
end;
end.
热心网友
时间:2022-04-26 21:50
program sb;
var
a:array[1..30,1..30]of integer;
i,j,m:integer;
begin
read(m);
for i:=1 to m do
for j:=1 to m do
begin
a[i,1]:=1;
if i=j then a[i,j]:=1{此处为数组赋值}
else a[i,j]:=a[i-1,j-1]+a[i-1,j];
end;
for i:=1 to m do
begin
write('');
for j:=1 to i do
write(a[i,j],' ');{输出所赋的值,OK}
writeln;
end;
end.