Skip to content

8. Reverse Triangle Star Pattern

Example

Pattern 8

\(N = 5\)

\[\Large
\begin{align}
    &\phantom{}*********\\
    &\phantom{*}*******\\
    &\phantom{**}*****\\
    &\phantom{***}***\\
    &\phantom{****}*\\
\end{align}
\]
printTriangle.cpp
#include <bits/stdc++.h>
using namespace std;

void printTriangle(int n) {
    for(int i=n; i>0; i--) {
        for(int j=n-i; j>0; j--) {
            cout << " ";
        }
        for(int k=0; k<2*i-1; k++) {
            cout << "*";
        }
        cout << endl;
    }
}

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

Input: 5
Output:

*********
 *******
  *****
   ***
    *