fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. int rows;
  7. // Getting the number of rows.
  8. cout << "Enter the Number of rows - ";
  9. cin >> rows;
  10.  
  11. cout << "Floyd's Triangle of " << rows << " rows." << endl;
  12.  
  13. // Main logic to print Floyd's Triangle.
  14. int counter = 1;
  15. for( int i = 0; i < rows; i++ ) {
  16. for( int j = 0; j <= i; j++ ){
  17. cout << (counter++) << " ";
  18. }
  19. cout << endl;
  20. }
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5300KB
stdin
6
stdout
Enter the Number of rows - Floyd's Triangle of 6 rows.
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21