Star Pattern Printer - Problem

Print a right-angled triangle pattern of stars with N rows.

The i-th row should contain exactly i stars, where i ranges from 1 to N.

Each row should be printed on a separate line with no trailing spaces.

Input & Output

Example 1 — Basic Triangle
$ Input: n = 4
Output: * ** *** ****
💡 Note: Row 1 has 1 star, row 2 has 2 stars, row 3 has 3 stars, row 4 has 4 stars
Example 2 — Minimum Size
$ Input: n = 1
Output: *
💡 Note: Single row with single star
Example 3 — Larger Triangle
$ Input: n = 5
Output: * ** *** **** *****
💡 Note: Five rows with 1, 2, 3, 4, and 5 stars respectively

Constraints

  • 1 ≤ n ≤ 1000

Visualization

Tap to expand
INPUT4Number of rows (N)Build triangle with4 rows of starsALGORITHM1Loop i from 1 to N2For row i, print i stars3Add newline after row4Repeat until completeRESULT**********Right-angled trianglewith 4 rowsKey Insight:Use nested loops where outer loop controls rows (1 to N) and inner loop prints exactly i stars for row iTutorialsPoint - Star Pattern Printer | Nested Loops
Asked in
TCS 15 Infosys 12
12.0K Views
High Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen