Facebook Pixel
Inverted Pyramid Star Pattern Logic

What is the math formula for stars in an inverted pyramid?

The answer

If counting rows 1 to N, the stars decrease according to the formula: 2 * (N - row) + 1.

More FAQs in Inverted Pyramid Star Pattern Logic

Take the exact code used for a normal pyramid, and simply change the outer loop to count down from N to 1 instead of 1 to N.

If counting rows 1 to N, the leading spaces increase according to the formula: row - 1.

Trailing spaces exist on the right side of the stars, but since there are no visible characters after them, printing a newline immediately achieves the exact same visual result and saves CPU cycles.

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.