Example 1 — Shrink the row with the outer loop
Start row at 5 and stop at 1. The inner loop prints 1 through row.
#include <iostream>
using namespace std;
int main() {
int rows = 5;
for (int row = rows; row >= 1; row--) {
for (int n = 1; n <= row; n++)
cout << n;
cout << '\n';
}
return 0;
} How It Works
row--makes each later line one digit shorter.- The inner
foralways restarts at 1, so every row begins with 1. cout << nprints theint;cout << '\n'ends the row.

