Shape Rule
rows..i per row
Every row starts at rows — row with stop i = 4 prints 5432; last row prints 54321.

Program 8 prints a reverse left-growing number triangle: each row begins with the peak digit rows and grows by adding the next smaller digit to the right — 5, 54, 543, and so on. This tutorial covers the shape rule, descending outer loop, inner bound rows..i, a live preview, worked C examples, edge cases, and complexity.
rows..i per row
Every row starts at rows — row with stop i = 4 prints 5432; last row prints 54321.
i = rows..1
for (i = rows; i >= 1; i--) — moves the inner stop point from rows down to 1.
j = rows..i
for (j = rows; j >= i; j--) always starts at rows, counts down to i.
Same line / next line
Digits use printf("%d", j); end each row with printf("\n").
rows = 3..9
Pick row count and draw the left-growing triangle in the browser.
Complexity
Total prints = 1+2+…+n = n(n+1)/2 — a triangular number.
A reverse left-growing number triangle keeps the same starting digit on every row while adding one more digit to the right each time. With rows = 5, you get 5, 54, 543, 5432, 54321.
In C use an outer loop counting down from rows to 1, an inner loop printing j from rows down to i, then printf("\n") after each row.
It pairs with Program 7’s right-growing triangle — fixed inner start at rows teaches how stop values control row width.
i = rows..1 — stop moves inward.
Fixed start at rows, stop at i.
Program 7 outer up, inner i..1; Program 8 outer down, inner rows..i.
Follow Program 7; continue to Program 9 next.
In short: outer i = rows..1, inner j = rows..i, printf("%d", j) per digit, then printf("\n").
Given row count rows = 5, print a reverse left-growing number triangle — inner loop prints digits rows..i on each row.
// rows = 5
//5
//54
//543
//5432
//54321 | Item | Type | Description |
|---|---|---|
rows | int | Triangle height — also the peak digit and inner loop start. |
i (outer) | int | Inner loop stop — runs rows down to 1. |
j (inner) | int | Prints rows..i with printf("%d", j). |
| Row width | int | Row with stop i prints rows - i + 1 digits. |
| First row | int | Single digit rows when i = rows. |
| Last row | string | Digits rows..1 when i = 1. |
for i from rows down to 1:
for j from rows down to i:
print j
print newline | Approach | Idea | Best for |
|---|---|---|
| Descending outer | for (i = rows; i >= 1; i--) | Stop value moves from peak to 1 |
| Inner rows..i | Fixed start at rows, countdown to i | Left-aligned peak digit |
| User-input rows | scanf | Flexible height |
| Compact trace | rows = 3 on paper first | Quick dry-runs |
| Spaced output | printf("%d ", j) | Readable columns |
| Goal | Pattern |
|---|---|
| Outer loop | for (i = rows; i >= 1; i--) |
| Inner loop | for (j = rows; j >= i; j--) printf("%d", j); |
| End row | printf("\n"); |
| Program 7 contrast | Program 7: outer up, inner i..1; Program 8: outer down, inner rows..i |
Same reverse left-growing triangle — three ways to set row count and trace the logic.
rows = 5Hard-coded height for demos
scanfRead row count from console
rows = 3Quick dry-run on paper
i = rows..1Descending stop value
j = rows..iFixed start at rows
Reach for this pattern when teaching fixed inner starts, variable inner stops, and comparing shapes with Program 7.
Natural companion to Program 7 — same triangular print count, fixed start at rows instead of growing from 1.
Fixed inner start rows with changing stop i — concrete bound practice.
Classic nested-loop question — explain outer down, inner rows..i before coding.
Compare this left-growing triangle with the next pattern in the series.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in fixed inner starts, variable stops, and O(n²) thinking.
Choose a row count between 3 and 9 and draw the reverse left-growing number triangle in the browser.
Three complete C programs — fixed rows, user input, and a compact trace with rows = 3. Click View Output to reveal sample console results.
Print five rows of the reverse left-growing number triangle with nested loops.
rows = 5Hard-coded height — outer loop down, inner loop from rows to i.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
for (i = rows; i >= 1; i--) {
for (j = rows; j >= i; j--)
printf("%d", j);
printf("\n");
}
return 0;
} Outer i runs 5 down to 1 — inner j always starts at rows and counts down to i.
Read row count from the user with validation.
Configurable height with scanf and a positive-rows check.
#include <stdio.h>
int main() {
int rows;
int i, j;
printf("Enter the number of rows: ");
if (scanf("%d", &rows) != 1 || rows <= 0) {
printf("Please enter a positive integer.\n");
return 1;
}
for (i = rows; i >= 1; i--) {
for (j = rows; j >= i; j--)
printf("%d", j);
printf("\n");
}
return 0;
} Same nested loops — only the row count comes from console input with safe parsing.
Use rows = 3 for a quick paper trace before larger triangles.
rows = 3 TraceSmall triangle — easy to dry-run on paper before scaling up.
#include <stdio.h>
int main() {
int rows = 3;
int i, j;
for (i = rows; i >= 1; i--) {
for (j = rows; j >= i; j--)
printf("%d", j);
printf("\n");
}
return 0;
} Three rows, six total digits — trace i and j on paper before coding rows = 5.
int rows = 5; sets the peak digit and pattern height.
for (i = rows; i >= 1; i--) moves the inner stop from 5 down to 1.
for (j = rows; j >= i; j--) always starts at rows, counts down to i.
printf("\n") moves to the next row after each line is printed.
Total printed digits follow triangular numbers: n(n+1)/2, so time complexity is O(n²).
rows = 5Trace each row — outer i is the inner stop, inner j runs from rows down to i.
| Stop (i) | Inner j values | Output line |
|---|---|---|
| 5 | 5 | 5 |
| 4 | 5, 4 | 54 |
| 3 | 5, 4, 3 | 543 |
| 2 | 5, 4, 3, 2 | 5432 |
| 1 | 5, 4, 3, 2, 1 | 54321 |
Total digits printed: 1+2+3+4+5 = 15 = 5×6/2 — the fifth triangular number.
Where this fixed-start countdown pattern shows up beyond the homework prompt.
Inner always begins at rows — teaches how stop values control width.
Example: trace row with i = 3 and watch j print 5, 4, 3.
Program 7 grows from the right starting at 1; Program 8 starts every row at the peak digit.
Example: print both patterns side by side for rows = 5.
Practice printf vs printf("\n") without complex math.
Example: put printf("\n") inside the inner loop by mistake.
Same outer loop — flip inner to ascending for Program 6’s left-growing pattern.
Example: change inner to j = i..rows with j++.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 → 55.
Pair the pattern with scanf and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain fixed inner start and changing stop first — then write the loops.
Why this pattern earns a permanent spot in beginner C courses.
Wrong inner start or stop shows up immediately — every row should begin with the peak digit.
Only loops and console output — no arrays or math libraries.
Add spaces, right-align, or flip inner direction with small edits.
Streaming output needs no storage beyond loop counters.
Pro Tip: trace i and j on paper for rows = 3 before coding — watch each row add one digit on the right.
Small habits that keep reverse left-growing triangle code clean.
Always begin inner loop at j = rows — only the stop i changes per row.
Avoid crashes when the user types letters instead of a number.
Only call printf("\n") after the inner loop finishes the row.
Outer i-- and inner j-- — both move toward smaller values.
Trace rows = 3 on paper before coding larger demos.
Pro Tip: if rows no longer start with the peak digit, check whether inner start was changed from rows to i.
Mistakes that commonly break reverse left-growing number triangles.
Rows no longer share the same leading digit — pattern breaks visually.
→ Use for (j = rows; j >= i; j--).
All digits print on one long line without a row break.
→ Call printf("\n") after the inner loop.
Invalid input may print nothing or behave unexpectedly.
→ Validate rows > 0 before the loops.
Letters or empty input leave rows unread when scanf is unchecked.
→ Check scanf return value and re-prompt on failure.
Ascending digits within each row produce the wrong shape.
→ Inner loop must count down from rows to i.
Check these inputs before calling the solution done.
Prints only 1 — inner loop runs once with j = 1.
Outer loop never runs — print nothing or show a message.
Output 2 then 21 — good quick test.
Reject with validation — outer loop condition fails silently otherwise.
Unchecked scanf leaves rows uninitialized — check the return value.
Still O(n²) prints — cap rows for console demos.
Try these variations to lock in the pattern.
j = i..rows with j++rows = 3 before codingj = rows — every row starts with the peak digit.n(n+1)/2 — a triangular number. For rows = 5, that is 15 digits.i..rows; Program 8 uses descending inner rows..i — same outer loop.rows down to 1 — e.g. 54321 when rows = 5.Quick Takeaway: outer i = rows..1, inner j = rows..i, printf("%d", j), then printf("\n").
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Compact trace (Example 3) | O(rows²) | O(1) |
The reverse left-growing number triangle is a compact nested-loop exercise: fixed inner start at rows, changing stop i, and each row grows one digit wider to the right. Master the fixed rows = 5 version, then try user input with scanf and the compact rows = 3 trace.
Practice the three examples above, then continue to Program 9 for the next pattern in the series.
Keep inner start at rows, count down to stop i, and validate row count when reading from the console.
for (j = rows; j >= i; j--)printf("\n") after each inner looprows > 0 for user inputrows = 3 on paper firsti instead of rowsj++ when the pattern needs countdownprintf("\n") inside the inner looprows = 3 dry-run before larger demosPrint the reverse left-growing number triangle the beginner-friendly way.
Row prints rows..i
Definitioni = rows..1
Loopj = rows..i
Loopprintf then newline
I/OO(n²) time
AnalysisEach row starts at rows and counts down to i — outer i runs rows..1, inner j prints rows..i — producing 5, 54, 543, and so on. Total prints grow as O(n²).
Move on to the next pattern in the C number-pattern series.
11 people found this page helpful