This code prints a right-angled triangle made of numbers with 8 rows, where the first row has 1 number and each subsequent row has one additional number.
i
and j
are integer variables declared at the beginning of the main
function.for
loop runs from 1 to 8, with i
incrementing by 1 each time.for
loop runs from 1 to the current value of i
, with j
incrementing by 1 each time.i
is printed to the console using the cout
statement.cout << endl;
.#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 1; i <= 8; i++) {
for (j = 1; j <= i; j++) {
cout << i;
}
cout << endl;
}
return 0;
}
1
22
333
4444
55555
666666
7777777
88888888