Print Alphabet Pattern (A to Z triangle)

Print Alphabet Pattern (A to Z triangle)

Hard C++ Pattern Printing 29 views
Explanation Complexity

Problem Statement

Print letters in triangular pattern.
Real Life: Understanding character printing in patterns.

Input Format

An integer n (number of rows).

Output Format

Letters printed in a triangular pattern.

Example

4
A
A B
A B C
A B C D

Constraints

• n ≥ 1

• Use uppercase English letters

• Pattern grows row by row

Concept Explanation

Letters are printed in a triangle shape.
Each row starts from A and prints one more letter than the previous row.
This helps understand character handling and nested loops.

Step-by-Step Explanation

1.Take input n.

2.Start outer loop from row 1 to n.

3.For each row i:

• Start character from 'A'.

4.Inner loop runs from 1 to i:

• Print current character.

• Move to next character using ch++.

5.After inner loop, move to next line.

Concept Explanation

Letters are printed in a triangle shape.
Each row starts from A and prints one more letter than the previous row.
This helps understand character handling and nested loops.

Step-by-Step Explanation

1.Take input n.

2.Start outer loop from row 1 to n.

3.For each row i:

• Start character from 'A'.

4.Inner loop runs from 1 to i:

• Print current character.

• Move to next character using ch++.

5.After inner loop, move to next line.

Input / Output Format

Input Format
An integer n (number of rows).
Output Format
Letters printed in a triangular pattern.
Constraints
• n ≥ 1

• Use uppercase English letters

• Pattern grows row by row

Examples

Input:
4
Output:
A A B A B C A B C D

Example Solution (Public)

C++
void pattern_q15_alphabet_triangle() {
    int n = 5;
    
    for(int i = 1; i <= n; i++) {
        char ch = 'A';
        for(int j = 1; j <= i; j++) {
            cout << ch << " ";
            ch++;
        }
        cout << endl;
    }
}

Official Solution Code

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

                                        
Please login to submit solutions.