Skip to content

5. Reverse Triangle Star Pattern

Example

Pattern 5

\(N = 5\)

\[\Large
\begin{align}
&*\; *\; *\; *\; *\\
&*\; *\; *\; *\\
&*\; *\; *\\
&*\; *\\
&*
\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=0; j<i; j++) {
            cout << "* ";
        }
        cout << endl;
    }
}

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

Input: 5
Output:

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