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

Number-Star Patterns

Number-star patterns mix digits and stars in one shape, for example 1, 2*2, 3*3*3. They train you to handle two kinds of output in the same row: a number on some positions and a star on the others.

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

All 6 number-star pattern programs

Tips for number-star patterns

  • Number the positions in a row from 1. Odd positions usually hold numbers and even positions hold stars.
  • Work out the value for an odd position first, then add the star rule.
  • Keep n small (up to 9) if you print numbers without spaces, so the shape stays clear.

Frequently asked questions

What is a number-star pattern?

A pattern that prints numbers and stars together, for example 1*2*3*4 or 3*3*3. The number and the star usually alternate along each row.

How do I decide where the stars go?

Count the positions in the row. If the row has 2i − 1 positions, the odd ones hold numbers and the even ones hold the i − 1 stars between them.

Can I use a different separator?

Yes. Replace the star with any character, such as a dash or a comma, and the logic stays the same.

More pattern programs