用PASCAL程序打印下列图形

2024-12-15 21:06:42
推荐回答(3个)
回答1:

1:
var
a,b,c:integer;
begin
for b:=1 to 7 do
begin
for c:=b to 2*b-1 do
begin
a:=c mod 10;
write(a,' ');
end;
for c:=2*b-2 downto b do
begin
a:=c mod 10;
write(a,' ');
end;
writeln;
end;
end.
2:
var
z:array[1..7,1..7] of integer;
a,b,c:integer;
begin
for a:=1 to 7 do
for b:=1 to 7 do
z[a,b]:=0;
for a:=1 to 7 do
for b:=1 to a do
for c:=a downto 1 do
if c=1 then
z[a+1,1]:=z[1,a]+1
else z[b+1,c-1]:=z[b,c];
for a:=1 to 7 do
for b:=1 to 7 do
begin
if z[a,b]<>0 then
write(z[a,b],' ');
writeln;
end;
end.

回答2:

第一题大概写了个,直接写的,木有编译过,不知道有没错。
我当你总共N行做的,如果你是指定值,加个给N的赋值就好了
program t1;
var n,i,j,k,m:integer;
a:array[1..100] of integer;
begin
readln(n)
for i:=1 to n do
begin
m:=2*n-1;
for j:=i to n-1 do write(" ");
k:=n;
for j:=1 to n do
begin
a[j]:=k;
a[2*i-j]:=k;
inc(k);
if k>9 then k=0;
end;
for j:=1 to 2*i-1 do write"a[j]";
for j:=i+1 to n do write" "
writeln;
end;
end.
啊,好久没打PASCAL了,可能有错,你自己改一下吧,空格不知道对得齐不齐呢。。。第二题其实也差不多的,你可以拿个二维数组存一下,然后再行列交换过来输出,调整一下间隔就好了。

回答3:

很简单的