Number Triangle
Given a positive integer n, print a left-aligned number triangle. Row 1 contains the number 1, row 2 contains 1 2, row 3 contains 1 2 3, and so on. Row i…
Given a positive integer n, print a left-aligned number triangle. Row 1 contains the number 1, row 2 contains 1 2, row 3 contains 1 2 3, and so on. Row i lists the numbers 1 through i. Unlike Floyd's Triangle, the count restarts from 1 at the beginning of every row. Numbers within each row are separated by a single space. Each row appears on its own line. There is no trailing space at the end of any row. For n = 4, the output is: 1 1 2 1 2 3 1 2 3 4
- `1 <= n <= 10` - `n` is always a positive integer.
Example 1: input n = 3; output 1 1 2 1 2 3. Row 1 has [1]. Row 2 restarts: [1, 2]. Row 3 restarts: [1, 2, 3]. Every row begins counting again from 1.
Example 2: input n = 5; output 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5. Each row i lists 1 through i. Row 4 is [1, 2, 3, 4] and row 5 is [1, 2, 3, 4, 5]. Total numbers = 15.
Example 3: input n = 1; output 1. With only one row, the triangle contains the single number 1.
Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.