Shape Rule
i..rows per row
Row with outer i = 5 prints 5; row with i = 1 prints 12345 — digits grow from the left.

Program 6 prints a reverse ascending number triangle: each row adds one digit on the left until the last row shows 1..rows — the mirror companion to Program 5’s growing triangle. This tutorial covers the shape rule, descending outer loop, inner bound i..rows, a live preview, worked C examples, edge cases, and complexity.
i..rows per row
Row with outer i = 5 prints 5; row with i = 1 prints 12345 — digits grow from the left.
i = rows..1
for (i = rows; i >= 1; i--) — start value moves leftward from the peak digit down to 1.
j = i..rows
for (j = i; j <= rows; j++) prints from the current start digit up to rows.
Same line / next line
Digits use printf("%d", j); end each row with printf("\n").
rows = 3..9
Pick row count and draw the reverse ascending triangle in the browser.
Complexity
Total prints = 1+2+…+n = n(n+1)/2 — same triangular number as Program 5.
A reverse ascending number triangle grows digits from the left: the first row shows only the peak digit, and each next row adds one more number on the left until the last row shows 1..rows. With rows = 5, you get 5, 45, 345, 2345, 12345.
In C use an outer loop counting down from rows to 1, an inner loop printing j from i to rows, then printf("\n") after each row.
It pairs with Program 5’s ascending triangle — changing the outer direction and inner start teaches how loop bounds control shape.
i = rows..1 — peak row first.
Fixed end at rows, start moves left.
Program 5 outer counts up, inner 1..i; Program 6 outer counts down, inner i..rows.
Follow Program 5; continue to Program 7 next.
In short: outer i = rows..1, inner j = i..rows, printf("%d", j) per digit, then printf("\n").
Given row count rows = 5, print a reverse ascending number triangle — row outer index i shows digits i..rows.
// rows = 5
//5
//45
//345
//2345
//12345 | Item | Type | Description |
|---|---|---|
rows | int | Triangle height — also the peak digit and inner loop end. |
i (outer) | int | Current row start — runs rows down to 1. |
j (inner) | int | Prints i..rows with printf("%d", j). |
| Row width | int | Row with outer i prints rows - i + 1 digits. |
| First row | int | Single digit rows when i = rows. |
| Last row | string | Digits 1..rows when i = 1. |
for i from rows down to 1:
for j from i to rows:
print j
print newline | Approach | Idea | Best for |
|---|---|---|
| Descending outer | for (i = rows; i >= 1; i--) | Peak-first row order |
| Inner i..rows | Start moves left, end fixed at rows | Left-growing triangle |
| 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 = i; j <= rows; j++) printf("%d", j); |
| End row | printf("\n"); |
| Program 5 contrast | Program 5: outer up, inner 1..i; Program 6: outer down, inner i..rows |
Same reverse ascending 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 row index
j = i..rowsFixed end at rows
Reach for this pattern when teaching descending outer loops, variable inner starts, and comparing shapes with Program 5.
Natural companion to Program 5 — same triangular print count, opposite growth direction.
Changing inner start i while keeping end rows fixed — concrete bound practice.
Classic nested-loop question — explain outer down, inner i..rows 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 descending outers, variable inner starts, and O(n²) thinking.
Choose a row count between 3 and 9 and draw the reverse ascending 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 ascending number triangle with nested loops.
rows = 5Hard-coded height — ideal for first demos and screenshots.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
for (i = rows; i >= 1; i--) {
for (j = i; j <= rows; j++)
printf("%d", j);
printf("\n");
}
return 0;
} When i = 5, the inner loop prints 5 only. When i = 1, it prints 12345 — each row adds one more digit on the left. printf("\n") after the inner loop starts the next row.
Let the user choose the height at runtime.
Read rows with scanf and validate the result.
#include <stdio.h>
int main() {
int rows;
int i, j;
printf("Enter the number of rows: ");
if (scanf("%d", &rows) != 1 || rows < 1)
return 1;
for (i = rows; i >= 1; i--) {
for (j = i; j <= rows; j++)
printf("%d", j);
printf("\n");
}
return 0;
} Same inner-loop core as Example 1; only the source of rows changes from a literal to user input.
Use rows = 3 for a quick paper trace before larger demos.
rows = 3Same loops with a smaller height — easy to dry-run on paper.
#include <stdio.h>
int main() {
int rows = 3;
int i, j;
for (i = rows; i >= 1; i--) {
for (j = i; j <= rows; j++)
printf("%d", j);
printf("\n");
}
return 0;
} Outer i runs 3, 2, 1; inner j prints i..rows each time. Trace this small case before scaling to rows = 5 or more.
#include <stdio.h> brings in printf and scanf. Set rows (fixed or from input).
for (i = rows; i >= 1; i--) selects the row start digit, beginning at the peak.
for (j = i; j <= rows; j++) prints digits i..rows with printf("%d", j).
printf("\n") ends the row so the next outer iteration starts fresh.
Total digit prints: 1+2+…+n = n(n+1)/2 — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value of i (counting down) and count how many digits the inner loop prints.
i | Inner j range | Printed row | Digits this row |
|---|---|---|---|
5 | 5..5 | 5 | 1 |
4 | 4..5 | 45 | 2 |
3 | 3..5 | 345 | 3 |
2 | 2..5 | 2345 | 4 |
1 | 1..5 | 12345 | 5 |
Total digit prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Clearest visual proof that outer and inner bounds interact.
Example: change inner start j = i and watch the left edge move.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: Program 5 grows each row from 1 to i; Program 6 grows from i to rows.
Practice printf vs printf("\n") without complex math.
Example: put printf("\n") inside the inner loop by mistake.
Swap digits for letters, stars, or spaced output once the loop works.
Example: print printf("%d ", j) for spaced digits on each row.
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 the outer/inner roles first — then write the loops. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner C courses.
Wrong bounds show up immediately as a broken staircase.
Only loops and console output — no arrays or math libraries.
Invert, center, hollow, or change the fill character 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 how each row adds one digit on the left.
Small habits that keep number-pattern code clean.
Use rows (or n) and keep i/j for row/column — or rename to row/col.
scanfAvoid crashes when the user types letters instead of a number.
Only call printf("\n") after the inner loop finishes the row.
rows..1 with inner j = i..rows matches “row i prints digits i..rows” naturally.
Trace rows = 3 on paper before coding larger demos.
Pro Tip: if the output is a vertical list of single digits, you almost certainly put printf("\n") inside the inner loop.
Mistakes that commonly break reverse ascending number triangles.
Each digit lands on its own line — you get a column, not a triangle.
→ Use printf("%d", j) for digits; printf("\n") only after the inner loop.
j = 1..i gives Program 5’s ascending triangle; j = 1..rows every row prints a full line.
→ For this shape, keep inner start at j = i and end at rows.
Omitting printf("\n") glues every digit onto one endless line.
→ Always end the row after the inner loop.
Letters or empty input leave rows unread when scanf is unchecked.
→ Check scanf return value and re-prompt on failure.
Switching to i = 0 without adjusting the inner bound prints an empty first row or wrong counts.
→ If 0-based, print digits (i+1)..rows (e.g. j = i + 1; j <= rows).
Check these inputs before calling the solution done.
Output is just the peak digit rows on one line (e.g. 1 when rows is 1).
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n²/2 characters — fine for labs, noisy for huge n.
Unchecked scanf leaves rows uninitialized — check the return value.
Try printf("%d ", j) for spaces between numbers.
Try these variations to lock in the pattern.
1..ii..rowsprintf("%d ", j) between digitsrows = 3 before codingn(n+1)/2 — hence O(n²) time.printf stays on the line; printf("\n") advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single peak digit.Quick Takeaway: outer loop counts down from rows, inner loop prints digits i..rows, then break the line — that is the whole pattern.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Compact trace (Example 3) | O(rows²) | O(1) |
The reverse ascending number triangle pattern is a small nested-loop exercise with lasting payoff: row/column thinking, printf vs printf("\n"), and O(n²) intuition. Master the fixed-rows version, then try user input and the compact rows = 3 trace.
Practice the three examples above, then continue to Program 7 for the next pattern in the series.
Row outer index i prints i..rows — keep printf("%d", j) for digits and printf("\n") for the break, and validate row counts when reading input.
for (i = rows; i >= 1; i--) in the outer loopprintf("%d", j) for digits and printf("\n") after each rowrows ≥ 1 for interactive programsscanf with return-value checks over unchecked readsprintf("\n") inside the inner digit looprows = 1 edge casePrint the triangle the beginner-friendly way.
Row i prints i..rows
DefinitionControls each row
CodePrints digits with printf("%d", j)
Codeprintf("\n") ends each row
O(n²) time
AnalysisThe outer loop starts from rows down to 1, and the inner loop prints i..rows — producing 5, 45, 345, and so on. Total prints still grow as O(n²).
Move on to the next pattern in the C number-pattern series.
11 people found this page helpful