TutorialStudyMite

Program to print inverted Floyd’s triangle star pattern in C++

JJuhi Kamdar1 min read
Beginner friendly

Track completion, mastery, and revision.

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.

  1. Take input from the user for the number of rows.
  2. Outer for loop will print the number of rows.
  3. 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






*

Finished reading?

Was this helpful?

Your feedback shapes better tutorials for everyone.