In this example, we’ll print Floyd’s triangle. Floyd’s triangle is a right-angled triangle. The Floyd’s triangle is as given below:

*
* *
* * *
*  * * *

Algorithm:

  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, i, c;
   cout<<"Enter the number of rows: ";
   cin>> n;
   cout<<"\n";
   for  (i = 1; i <= n; i++)
   {
      for  (c = 1; c<= i; c++)
      {
	cout<<"*";
      }
        cout<<"\n";
   }
   return  0;
}

Output:

Enter the number of rows: 5

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

[yuzo_views]












CopyRight © 2019

CopyRight © 2019