Pattern Programmings

        -2  -1  0   1   2
      +---+---+---+---+---+
   -2 | . | . | X | . | . |
      +---+---+---+---+---+
   -1 | . | X | O | X | . |
      +---+---+---+---+---+
    0 | X | X | O | X | X |
      +---+---+---+---+---+
    1 | . | X | O | X | . |
      +---+---+---+---+---+
    2 | . | . | X | . | . |
      +---+---+---+---+---+

Points are not drawn if (col = 0 and abs(row) != 2) or either row or col is 2 and other is non-zero. You can implement these conditions in your code.

For(row = -2 to 2)
  For(col = -2 to 2)
    if ( (col = 0 and abs(row) != 2) or (abs(row) = 2 and col != 0) or (abs(col) = 2 and row != 0) )
      draw space character
    else
      draw *
  line break

Leave a Comment