在PASCAL编程中绘制Pascal的三角形就像钻石一样

时间:2011-12-25 16:16:02

标签: pascal pascals-triangle

如何在PASCAL编程中绘制Pascal的三角形,就像我从输入中得到的那个钻石一样?

修改 我试过这个程序:

program Pascal_triangle;
var
i,j,n : integer;
A : Array[1..6,1..6] of Integer;
begin
   n := 6;
   for i:=1 to n do
   begin
      for j:=1 to i do
      begin
         if (j=1) or (i=j) then
         begin
            A[i,j]:=1;
         end
         else
         begin
            A[i,j] := A[i-1,j] + A[i-1,j-1];
         end;
      end;
   end;
   for i:=1 to n do
   begin
      Gotoxy(41-i,i);
      for j:=1 to i do
         write(A[i,j])
   end;
   readln;
end.

但我在gotoxy线上出错,我需要它是钻石。

1 个答案:

答案 0 :(得分:0)

2011年12月31日21:22 :谢谢,我写了这个并且有效

program Pascal_triangle;
var d,c,y,x,n : integer;
   begin
      readln(n);
      writeln;
      for y:=0 to n do
      begin
         c:=1;
         for d:=0 to n - y do
         begin
            write(' ');
         end;
         for x:=0 to y do
         begin
            write(c);
            write(' ');
            c := c * (y - x) DIV (x + 1);
         end;
         writeln;
      end;
      for y:=n-1 downto 0 do
      begin
         c:=1;
         for d:=0 to n - y do
         begin
            write(' ');
         end;
         for x:=0 to y do
         begin
            write(c);
            write(' ');
            c := c * (y - x) DIV (x + 1);
         end;
         writeln;
      end;
      readln;
   end.