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

Hash (#) Right Triangle
A right-angled triangle drawn with the # symbol.

Dollar ($) Pyramid
A centred pyramid drawn with the $ symbol.

Plus (+) Sign Pattern
A plus sign drawn on an n × n grid (use an odd n).

X (Cross) Pattern
The two diagonals of a square, forming the letter X.

Hollow Square with @
The border of a square drawn with @.

Checkerboard Pattern
Alternating # and . cells, like a chess board.
Tips for symbol patterns
- For shapes on a square grid, write a single condition in terms of
iandjthat 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.
