Print Floyd's Triangle. 1 2 3 4 5 6 7 8 9 10 Test Case 1 Input (stdin) 4 Expected Output 1 2 3 4 5 6 7 8 9 10 Test Case 2 Input (stdin) 8 Expected Output 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 29 30 31 32 33 34 35 36
// C++ program to print Floyd's triangle
#include <iostream>
using namespace std;
int main() {
int i, j, rows, counter;
//cout << "Enter the number of rows of Floyd's triangle\n";
cin >> rows;
// Print Floyd's triangle
for (counter = 1, i = 1; i <= rows; i++) {
// Print ith row
for (j = 1; j <= i; j++) {
cout << counter++ << " ";
}
cout << endl;
}
return 0;
}