New: 77 pattern programs with tested code in C, C++, Java and Python Explore patterns

Symbol Patterns

Symbol patterns use characters such as #, $, @ and + to draw shapes. The logic is the same as star patterns, but many of these shapes are drawn by testing a condition for every cell of a square grid, for example “is this cell on a diagonal?” or “is this cell on the border?”

Pick a pattern to see its output, a row-by-row diagram and the full program in C, C++, Java and Python.

All 6 symbol pattern programs

Tips for symbol patterns

  • For shapes on a square grid, write a single condition in terms of i and j that is true exactly where the symbol should appear.
  • Print the symbol and the blank with the same width (for example "# " and " ") so the columns stay aligned.
  • Plus and X shapes look best with an odd n, so there is a single middle row and column.

Frequently asked questions

What is the difference between symbol patterns and star patterns?

Only the character changes. The loops and conditions are the same, so any star pattern can become a symbol pattern by printing a different character.

How do I print a pattern with a symbol entered by the user?

Read a character into a variable (for example char ch) and print that variable instead of the fixed symbol.

Why is the X pattern condition i + j == n + 1?

On the anti-diagonal, the row number increases as the column number decreases, so their sum stays constant at n + 1.

More pattern programs