pascal问题 杨辉三角
有错吗vara:array[1..10,1..13]ofinteger;i,j,k,s:integer;beginread(s);fori:=1tosdobeginfor...
有错吗
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;
readln;
readln;
end.
问题 C: 二维数组——3、杨辉三角
时间限制: 1 Sec 内存限制: 128 MB
提交: 32 解决: 9
[提交][状态][讨论版]
题目描述
输出杨辉三角的前N行。
输入
输入正整数N(N<=10)
输出
输出杨辉三角的前N行。
样例输入
6
样例输出
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1 展开
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;
readln;
readln;
end.
问题 C: 二维数组——3、杨辉三角
时间限制: 1 Sec 内存限制: 128 MB
提交: 32 解决: 9
[提交][状态][讨论版]
题目描述
输出杨辉三角的前N行。
输入
输入正整数N(N<=10)
输出
输出杨辉三角的前N行。
样例输入
6
样例输出
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1 展开
3个回答
展开全部
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.
更多追问追答
追问
评测系统说这是格式错误
追答
var
n,i,j:integer;
a:array[0..20,0..20] of integer;
begin
readln(n);
for i:=1 to n do
for j:=0 to i do
if (j=0)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:=0 to i do write(a[i,j],' ');
writeln;
end;
end.
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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.
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.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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.
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.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询