Print Number Pattern (1 to N)

Print Number Pattern (1 to N)

Easy C++ Pattern Printing 44 views
Explanation Complexity

Problem Statement

Print numbers instead of stars in pattern.
Real Life: Understanding value printing in patterns.

Input Format

An integer n (number of rows).

Output Format

Centered pyramid pattern printed using numbers.

Example

4
   1
  121
 12321
1234321

Constraints

1.n ≥ 1

2.Use loops only

3.Numbers increase then decrease

Concept Explanation

Instead of stars, numbers are printed.
Each row prints numbers increasing from 1, then decreasing back to 1,
while spaces keep the pattern centered.

Step-by-Step Explanation

1.Take input n.

2.Loop row i from 1 to n.

3.Print (n - i) spaces.

4.Print numbers from 1 to i (increasing).

5.Print numbers from i-1 down to 1 (decreasing).

6.Move to next line.

Concept Explanation

Instead of stars, numbers are printed.
Each row prints numbers increasing from 1, then decreasing back to 1,
while spaces keep the pattern centered.

Step-by-Step Explanation

1.Take input n.

2.Loop row i from 1 to n.

3.Print (n - i) spaces.

4.Print numbers from 1 to i (increasing).

5.Print numbers from i-1 down to 1 (decreasing).

6.Move to next line.

Input / Output Format

Input Format
An integer n (number of rows).
Output Format
Centered pyramid pattern printed using numbers.
Constraints
1.n ≥ 1

2.Use loops only

3.Numbers increase then decrease

Examples

Input:
4
Output:
1 121 12321 1234321

Example Solution (Public)

C++
void pattern_q4_number_pattern() {
    int n = 5;
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= i; j++) {
            cout << i << " ";
        }
        cout << endl;
    }
}

Official Solution Code

void pattern_q4_number_pattern() {
    int n = 5;
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= i; j++) {
            cout << i << " ";
        }
        cout << endl;
    }
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.