Skip to content

16. Triangle Character Pattern

Example

Pattern 16

\(N = 5\)

\[\Large
\begin{align}
&A\\
&BB\\
&CCC\\
&DDDD\\
&EEEEE\\
\end{align}
\]
printTriangle.cpp
#include <bits/stdc++.h>
using namespace std;

void printTriangle(int n) {
    char ch = 'A';
    for(int i=1; i<=n; i++) {
        for(int j=0; j<i; j++) {
            cout << ch;
        }
        ch++;
        cout << endl;
    }
}

int main(void) {
    int n;
    cin >> n;
    printTriangle(n);
    return 0;
}

Input: 5
Output:

A
BB
CCC
DDDD
EEEEE