fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int num_rows;
  6.  
  7. // Prompting the user to enter the number of rows.
  8. cout << "Enter the number of rows: ";
  9. cin >> num_rows;
  10.  
  11. cout << "Floyd's Triangle with " << num_rows << " rows:" << endl;
  12.  
  13. // Printing Floyd's Triangle.
  14. int number = 1;
  15. for (int row = 0; row < num_rows; row++) {
  16. // Printing numbers for each row.
  17. for (int col = 0; col <= row; col++) {
  18. cout << number++ << " ";
  19. }
  20. cout << endl; // Move to the next line for the next row.
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5304KB
stdin
7
stdout
Enter the number of rows: Floyd's Triangle with 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