Facebook Pixel
How to Print a Right-Angled Triangle Pattern

What is the key to printing a right-angled triangle?

The answer

The key is making the inner loop's termination condition dynamically dependent on the outer loop's counter (e.g., col <= row).

More FAQs in How to Print a Right-Angled Triangle Pattern

The inner loop will lose its dynamic dependency and will always print N stars, resulting in a square instead of a triangle.

Yes, simply replace the print statement. If you print 'col', it will output '1', '12', '123'. If you print 'row', it will output '1', '22', '333'.

It is O(N^2). Even though the inner loop runs fewer times initially, mathematically it executes roughly (N^2)/2 times, which simplifies to O(N^2).

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.