solutions/cw4/pascal.while
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 18 Oct 2024 05:59:04 +0100
changeset 970 1d4659dd83fe
parent 959 64ec1884d860
permissions -rw-r--r--
updated

rows := 13;
coef := 1;

i := 0;
while (i < rows) do {

  space := 1;

  while (space <= rows - i) do {
      write("  ");
      space := space + 1
  };

  j := 0;
  while (j <= i) do {

      if ((j == 0) || i == 0) then {
        coef := 1
      } else {
        coef := (coef * ((i - j) + 1)) / j
      };

      if (coef < 10) then write("   ") else 
      if (coef < 100) then write("  ") else
      if (coef < 1000) then write(" ")
      else skip;

      write(coef);
      j := j + 1
  };


  write("\n");
  i := i + 1
}