Program to Print Floyd’s Triangle Pattern in C++

In this article, we will learn how to Print Floyd’s Triangle Pattern in C++. To print Floyd’s pattern nested loop is used.

Desired Output for 7 rows:
   1
   2    3
   4    5    6
   7    8    9   10
  11   12   13   14   15
  16   17   18   19   20   21
  22   23   24   25   26   27   28

C++ Program for the Floyd’s Triangle Pattern


#include <iostream>
using namespace std;
int main()
{
   int size, num=1;

  cout<<"Please enter the size for Floyd Triangle: ";
  cin>>size;

   for(int row=1; row<= size; row++)
   {
     for(int col = 1; col <= row; col++) 
     cout<<num++;

     cout<<"\n";
   }

   return 0;
}

Output

Please enter the size for Floyd Triangle: 7
1
23
456
78910
1112131415
161718192021
22232425262728