Facebook Pixel
Printing a Pyramid Star Pattern (Spaces and Stars)

What is the formula for leading spaces in a pyramid?

The answer

If N is the total height and 'row' is the current row, the formula for leading spaces is N - row.

More FAQs in Printing a Pyramid Star Pattern (Spaces and Stars)

Because you must print a specific, mathematically decreasing number of invisible space characters before you can print the mathematically increasing stars.

No. They are placed sequentially (one after the other) inside the outer loop. The space loop finishes completely before the star loop begins.

The stars follow the odd-number sequence, which is mathematically represented as (2 * row) - 1.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.