Descending Left-Growing Number Pattern in C

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

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.

Shape Rule

rows..i per row

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

Outer Loop

i = rows..1

for (i = rows; i >= 1; i--) — moves the inner stop point from rows down to 1.

Inner Loop

j = rows..i

for (j = rows; j >= i; j--) always starts at rows, counts down to i.

printf vs newline

Same line / next line

Digits use printf("%d", j); end each row with printf("\n").

Live Preview

rows = 3..9

Pick row count and draw the left-growing triangle in the browser.

O(n²)

Complexity

Total prints = 1+2+…+n = n(n+1)/2 — a triangular number.

Introduction

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.

Why it matters?

It pairs with Program 7’s right-growing triangle — fixed inner start at rows teaches how stop values control row width.

Key Highlights

Outer down

i = rows..1 — stop moves inward.

Inner rows..i

Fixed start at rows, stop at i.

vs Program 7

Program 7 outer up, inner i..1; Program 8 outer down, inner rows..i.

Series Step

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").

📝 Problem & Approach

Given row count rows = 5, print a reverse left-growing number triangle — inner loop prints digits rows..i on each row.

c
// rows = 5
//5
//54
//543
//5432
//54321

Inputs & Outputs

ItemTypeDescription
rowsintTriangle height — also the peak digit and inner loop start.
i (outer)intInner loop stop — runs rows down to 1.
j (inner)intPrints rows..i with printf("%d", j).
Row widthintRow with stop i prints rows - i + 1 digits.
First rowintSingle digit rows when i = rows.
Last rowstringDigits rows..1 when i = 1.

Minimal workflow

Pseudocode
for i from rows down to 1:
    for j from rows down to i:
        print j
    print newline

Approach comparison

ApproachIdeaBest for
Descending outerfor (i = rows; i >= 1; i--)Stop value moves from peak to 1
Inner rows..iFixed start at rows, countdown to iLeft-aligned peak digit
User-input rowsscanfFlexible height
Compact tracerows = 3 on paper firstQuick dry-runs
Spaced outputprintf("%d ", j)Readable columns

⚡ Quick Reference

GoalPattern
Outer loopfor (i = rows; i >= 1; i--)
Inner loopfor (j = rows; j >= i; j--) printf("%d", j);
End rowprintf("\n");
Program 7 contrastProgram 7: outer up, inner i..1; Program 8: outer down, inner rows..i

📋 Fixed Rows vs User Input vs Compact Trace

Same reverse left-growing triangle — three ways to set row count and trace the logic.

Fixed rows
rows = 5

Hard-coded height for demos

User input
scanf

Read row count from console

Compact trace
rows = 3

Quick dry-run on paper

Outer
i = rows..1

Descending stop value

Inner
j = rows..i

Fixed start at rows

Context

When This Pattern Shows Up

Reach for this pattern when teaching fixed inner starts, variable inner stops, and comparing shapes with Program 7.

  1. Post Program 7 exercise

    Natural companion to Program 7 — same triangular print count, fixed start at rows instead of growing from 1.

  2. Loop bound drills

    Fixed inner start rows with changing stop i — concrete bound practice.

  3. Interview warm-ups

    Classic nested-loop question — explain outer down, inner rows..i before coding.

  4. Gateway to Program 9

    Compare this left-growing triangle with the next pattern in the series.

  5. Not a UI layout tool

    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.

🔮 Live Preview

Choose a row count between 3 and 9 and draw the reverse left-growing number triangle in the browser.

Try 4, 5, or 7. Max up to 9 in this preview.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed rows, user input, and a compact trace with rows = 3. Click View Output to reveal sample console results.

📚 Getting Started

Print five rows of the reverse left-growing number triangle with nested loops.

Example 1 — Fixed rows = 5

Hard-coded height — outer loop down, inner loop from rows to i.

c
#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;
}

How It Works

Outer i runs 5 down to 1 — inner j always starts at rows and counts down to i.

📈 Practical Variant

Read row count from the user with validation.

Example 2 — User Input Rows

Configurable height with scanf and a positive-rows check.

c
#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;
}

How It Works

Same nested loops — only the row count comes from console input with safe parsing.

⚡ Compact Trace

Use rows = 3 for a quick paper trace before larger triangles.

Example 3 — Compact rows = 3 Trace

Small triangle — easy to dry-run on paper before scaling up.

c
#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;
}

How It Works

Three rows, six total digits — trace i and j on paper before coding rows = 5.

🧠 How the Nested Loops Build Each Row

1

Choose the row count

int rows = 5; sets the peak digit and pattern height.

Setup
2

Outer loop (stop digit)

for (i = rows; i >= 1; i--) moves the inner stop from 5 down to 1.

Row control
3

Inner loop (print rows..i)

for (j = rows; j >= i; j--) always starts at rows, counts down to i.

Descending print
4

New line

printf("\n") moves to the next row after each line is printed.

Line break
=

Reverse left-growing triangle complete

Total printed digits follow triangular numbers: n(n+1)/2, so time complexity is O(n²).

🔎 Worked Walkthrough — rows = 5

Trace each row — outer i is the inner stop, inner j runs from rows down to i.

Stop (i)Inner j valuesOutput line
555
45, 454
35, 4, 3543
25, 4, 3, 25432
15, 4, 3, 2, 154321

Total digits printed: 1+2+3+4+5 = 15 = 5×6/2 — the fifth triangular number.

Use Cases

Where this fixed-start countdown pattern shows up beyond the homework prompt.

1. Fixed Inner Start

Inner always begins at rows — teaches how stop values control width.

Example: trace row with i = 3 and watch j print 5, 4, 3.

2. Pair with Program 7

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.

3. Output Formatting Drills

Practice printf vs printf("\n") without complex math.

Example: put printf("\n") inside the inner loop by mistake.

4. Compare with Program 6

Same outer loop — flip inner to ascending for Program 6’s left-growing pattern.

Example: change inner to j = i..rows with j++.

5. Complexity Intuition

Triangular totals make O(n²) concrete for beginners.

Example: count printed digits for n = 10 → 55.

6. Input Validation Labs

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.

Advantages

Why this pattern earns a permanent spot in beginner C courses.

  1. 1. Instant Visual Feedback

    Wrong inner start or stop shows up immediately — every row should begin with the peak digit.

  2. 2. Minimal Concepts

    Only loops and console output — no arrays or math libraries.

  3. 3. Easy to Extend

    Add spaces, right-align, or flip inner direction with small edits.

  4. 4. O(1) Extra Memory

    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.

Usage Tips

Small habits that keep reverse left-growing triangle code clean.

  1. 1. Keep Inner Start Fixed

    Always begin inner loop at j = rows — only the stop i changes per row.

  2. 2. Check scanf return value

    Avoid crashes when the user types letters instead of a number.

  3. 3. Keep Newline Outside

    Only call printf("\n") after the inner loop finishes the row.

  4. 4. Count Down on Both Loops

    Outer i-- and inner j-- — both move toward smaller values.

  5. 5. Dry-Run One Small n

    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.

Common Pitfalls

Mistakes that commonly break reverse left-growing number triangles.

  1. 1. Starting Inner at i Instead of rows

    Rows no longer share the same leading digit — pattern breaks visually.

    → Use for (j = rows; j >= i; j--).

  2. 2. Forgetting Newline After Each Row

    All digits print on one long line without a row break.

    → Call printf("\n") after the inner loop.

  3. 3. Zero or Negative Rows

    Invalid input may print nothing or behave unexpectedly.

    → Validate rows > 0 before the loops.

  4. 4. Blind scanf

    Letters or empty input leave rows unread when scanf is unchecked.

    → Check scanf return value and re-prompt on failure.

  5. 5. Using j++ Instead of j--

    Ascending digits within each row produce the wrong shape.

    → Inner loop must count down from rows to i.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single row

Prints only 1 — inner loop runs once with j = 1.

rows = 0

Zero rows

Outer loop never runs — print nothing or show a message.

rows = 2

Minimal triangle

Output 2 then 21 — good quick test.

Negative

Negative rows

Reject with validation — outer loop condition fails silently otherwise.

Bad input

Non-numeric scanf

Unchecked scanf leaves rows uninitialized — check the return value.

Large n

Many rows

Still O(n²) prints — cap rows for console demos.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Compare with Program 7

  • Program 7: outer up, inner i..1
  • Program 8: outer down, inner rows..i

2. Flip to Program 6

  • Change inner to j = i..rows with j++
  • Same outer loop, ascending digits

3. Next in series

  • Continue with Program 9
  • Next number pattern in the series

4. Paper trace

  • Dry-run rows = 3 before coding
  • Fill the walkthrough table by hand

Notes

  • Fixed start. Inner loop always begins at j = rows — every row starts with the peak digit.
  • Total digits = n(n+1)/2 — a triangular number. For rows = 5, that is 15 digits.
  • Program 6 uses ascending inner i..rows; Program 8 uses descending inner rows..i — same outer loop.
  • The last row always shows digits from 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").

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
Compact trace (Example 3)O(rows²)O(1)
Wrap Up

🎉 Conclusion

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.

💡 Best Practices

✅ Do

  • Explain fixed inner start before coding
  • Use for (j = rows; j >= i; j--)
  • Call printf("\n") after each inner loop
  • Validate rows > 0 for user input
  • Dry-run rows = 3 on paper first
  • State O(n²) time when asked about complexity

❌ Don’t

  • Start inner loop at i instead of rows
  • Use j++ when the pattern needs countdown
  • Put printf("\n") inside the inner loop
  • Confuse this with Program 7’s right-growing triangle
  • Skip the rows = 3 dry-run before larger demos

Key Takeaways

Knowledge Unlocked

Five things to remember about this left-growing pattern

Print the reverse left-growing number triangle the beginner-friendly way.

5
Core concepts
02

Outer

i = rows..1

Loop
03

Inner

j = rows..i

Loop
W 04

Output

printf then newline

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

It prints a reverse left-growing number triangle: row 1 shows 5, row 2 shows 54, row 3 shows 543, and so on until the last row shows digits from rows down to 1.
The inner loop always starts at j = rows. Only the stopping value i changes, so each row begins with the peak digit.
When i = 1, the inner loop prints j from rows down to 1 — giving 54321 on the last line.
Program 7 outer counts up and prints i down to 1 (1, 21, 321). Program 8 outer counts down and inner always starts at rows (5, 54, 543).
Program 6 inner prints i..rows ascending (5, 45, 345). Program 8 inner prints rows..i descending (5, 54, 543) — same outer loop, opposite inner direction.
printf("%d", j) stays on the same line for each digit. printf("\n") ends the row after the inner loop finishes.
Change rows or read it from user input with scanf — see Example 2.
Yes — use an ascending inner loop for (j = i; j <= rows; j++) like Program 6.
O(n²) for n rows because total prints are 1 + 2 + ... + n = n(n+1)/2.
Check scanf return value: if (scanf("%d", &rows) != 1) handle bad input. Unchecked scanf leaves rows uninitialized on failure.

Did you Know? 🔊

Each 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²).

Continue to Program 9

Move on to the next pattern in the C number-pattern series.

Program 9 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful