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

Number-Star Triangle (1, 2*2, 3*3*3)
A right triangle where row i repeats the number i, with stars in between.

Inverted Number-Star Triangle
The number-star triangle upside down, starting with the widest row.

Consecutive Number-Star Triangle (1, 2*3, 4*5*6)
Floyd’s triangle with a star between neighbouring numbers.

Number-Star Half Diamond (Sandwich)
The number-star triangle followed by its inverse, so the rows grow and then shrink.

Row Number-Star Square (1*1*1*1)
Every row repeats its row number, joined with stars.

Number-Star Square (1*2*3*4)
Consecutive numbers fill a square, with a star between each pair of numbers.
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
nsmall (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.
