ProgramsC++

Pattern Programs

Star and number pattern programs in C++ built with nested for loops: half pyramids, full and inverted pyramids, a number triangle, and Pascal's triangle.

6 programs · open one, then the next

Start with Right Half Pyramid
  1. 01Right Half PyramidBeginnerPrint a right half pyramid of stars in C++ with two nested for loops. Learn how the outer loop picks the row and the inner loop prints i stars on row i.Open example →
  2. 02Left Half PyramidBeginnerPrint a left half pyramid in C++ by printing rows - i padding spaces before i stars on each line. Shows why the padding is two spaces wide to match "* ".Open example →
  3. 03Full PyramidIntermediatePrint a centered full pyramid of stars in C++ using rows - i spaces and 2i - 1 stars per row. Explains where the odd numbers come from and how to center it.Open example →
  4. 04Inverted PyramidIntermediatePrint an inverted centered pyramid in C++ by running the outer loop from rows down to 1. Same star and space formulas as the full pyramid, read in reverse.Open example →
  5. 05Number Pattern: 1 to Row TriangleBeginnerPrint a single number triangle in C++ where row i counts 1, 2, ... up to i. A beginner nested-loop lesson that swaps the star for the inner counter j.Open example →
  6. 06Pascal's TriangleAdvancedPrint Pascal's triangle in C++ with the running formula num = num * (i - j) / (j + 1). Explains binomial coefficients and why multiplying first stays exact.Open example →