Skip to content

15. Reverse Triangle Character Pattern

Example

Pattern 15

\(N = 5\)

\[\Large
\begin{align}
&ABCDE\\
&ABCD\\
&ABC\\
&AB\\
&A\\
\end{align}
\]
printTriangle.cpp
#include <bits/stdc++.h>
using namespace std;

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

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

Input: 5
Output:

ABCDE
ABCD
ABC
AB
A