Program to print inverted Floyd’s triangle star pattern in C++
Written by
In this example, we’ll print inverted Floyd’s triangle. The inverted Floyd’s triangle is as given below:
* * * * *
* * * *
* * *
* *
*
Algorithm:
The algorithm to print inverted Floyd’s triangle is similar to that of Floyd’s triangle.
- Take input from the user for the number of rows.
- Outer for loop will print the number of rows.
- The inner loop will print the star pattern.
Code:
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter number of rows: ";
cin>>n;
cout<<"\n";
for (int i = n; i >= 1; --i)
{
for (int j = 1; j<= i; ++j)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}
Output:
Enter number of rows: 5
-
*