Printing the Flyod’s Triangle
Printing the Flyod’s triangle of numbers which are increasing in both row and column wise fashion
Learning Objectives
- Printing the typical Flyod’s Triangle with the help of nested for loops.
Source Code
|
|
Related ( ? ) : |
Run Output
Code Understanding
int cnt; //The row count will be collected by the the user
int k=1; //This is the beginning number from where the Flyod’s triangle will start
cout<<“Give row count: “; cin>>cnt; //Here we collect the row count
for(int i=1;i<=cnt;i++) //This outer loop is for row increment
{
for(int j=1;j<=i;j++) //This inner loop is for column increment
{
cout<<k<<” “; //The printed count begins here
k++; //In each iteration it is incremented whether it is row or column
}
cout<<endl; //New line after each row, so it is given in the outer loop
}
}
Notes
- Flyod’s triangle has some interesting mathematical properties. See them here.
https://en.wikipedia.org/wiki/Floyd%27s_triangle
Suggested Filename(s): flyods-triangle.cpp,flyods.cpp
Created: 20-Jan-2018 19:38 | Updated: 1-Mar-2026 17:10|
