0-Centered Descending Mirror Number Pattern in C

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

What You’ll Learn

The 0-centered descending mirror pattern prints 0, 909, 89098, … up to 1234567890987654321 — a natural step after the palindrome triangle in Program 27. This tutorial covers three nested loops, a fixed zero center, a live preview, algorithm steps, worked C examples, edge cases, and complexity.

Shape Rule

0 at center

Each row is ascending digits, 0, then descending digits — a mirror around zero.

Outer Loop

i = 10..1

for (i = 10; i >= 1; i--) — descending outer loop grows each row.

Left Loop (j)

i..9

for (j = i; j < 10; j++) prints the ascending left half.

Right Loop (k)

9..i

for (k = 9; k >= i; k--) mirrors digits after the zero.

Live Preview

max 3–9

Pick a max digit and draw the 0-centered mirror pattern in the browser.

O(n²)

Complexity

Total prints grow as for max digit n.

Introduction

A 0-centered descending mirror number pattern prints ascending digits, a fixed 0, then descending digits on each row. With max digit 9, the output grows from 0 to 1234567890987654321.

In C you use a descending outer loop i = 10..1, ascending inner loop j = i..9, print 0, then descending inner loop k = 9..i.

Why it matters?

It introduces three coordinated loops with a fixed center — a step up from Program 27’s two-loop palindrome.

Key Highlights

Fixed 0 center

printf("0") between both inner loops.

Left j = i..9

Ascending digits grow as i decreases.

Right k = 9..i

Descending mirror completes each row.

Series Foundation

Follow Program 27; continue to Program 29 (spaced mirror) next.

In short: for each i from 10 down to 1, print i..9, then 0, then 9..i, then printf("\n").

📝 Problem & Approach

Given max digit 9, print 10 rows of a 0-centered mirror: for each descending i, print i..9, then 0, then 9..i on the same line.

c
// max = 9 (conceptual shape)
// 0
// 909
// 89098
// 7890987
// ...
// 1234567890987654321

Inputs & Outputs

ItemTypeDescription
maxintHighest digit on each side — typically 9; outer loop starts at max + 1.
iintDescending outer loop — controls how many digits appear on each side.
jintAscending loop — prints i..max (left half).
kintDescending loop — prints max..i (right half).

Minimal workflow

Pseudocode
for i from max+1 down to 1:
    for j from i to max:
        print j
    print 0
    for k from max down to i:
        print k
    print newline

Approach comparison

ApproachIdeaBest for
Three loops + 00, 909, 89098, …Learning and interviews
Custom max digitscanf("%d", &max);Flexible console programs
Spaced outputprintf("%d ", j)Easier reading for wide rows

⚡ Quick Reference

GoalPattern
Walk rowsfor (i = 10; i >= 1; i--)
Left halffor (j = i; j < 10; j++) printf("%d", j);
Center zeroprintf("0");
Right halffor (k = 9; k >= i; k--) printf("%d", k);
End the rowprintf("\n");
Custom maxfor (i = max + 1; i >= 1; i--) with j <= max, k >= i

📋 Fixed Max vs Custom Max vs Spaced Output

Same 0-centered mirror — different ways to control max digit and formatting.

Outer loop
i = max+1..1

Descending — grows each row

Left half
j = i..max

Ascending digits

Center
printf("0")

Fixed zero between loops

Learning tip
i = max+1

First row prints only 0

Context

When This Pattern Shows Up

Reach for this pattern when teaching three coordinated loops with a fixed center character.

  1. Post palindrome exercise

    Natural follow-up after Program 27 — introduces a fixed 0 center and descending outer loop.

  2. Nested-loop warm-up

    Outer/inner bound practice with an immediate visual check.

  3. Console I/O practice

    Combine loops with scanf for a flexible row count.

  4. Gateway to variants

    Compare Program 27 (palindrome triangle) and Program 29 (spaced mirror) next.

  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 nested loops, output sequencing, and O(n²) thinking.

🔮 Live Preview

Choose a max digit between 3 and 9 and draw the 0-centered mirror pattern in the browser.

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

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed max digit, custom max input, and spaced output variant. Click View Output to reveal sample console results.

📚 Getting Started

Print ten rows of the 0-centered mirror with max digit 9 and outer loop i = 10..1.

Example 1 — Fixed max = 9

Hard-coded max digit — ideal for first demos and screenshots.

c
#include <stdio.h>

int main() {
    int i, j, k;

    for (i = 10; i >= 1; --i) {
        for (j = i; j < 10; ++j)
            printf("%d", j);

        printf("0");

        for (k = 9; k >= i; --k)
            printf("%d", k);

        printf("\n");
    }

    return 0;
}

How It Works

When i = 10, both inner loops are empty — output is just 0. When i = 9, print 9, then 0, then 9 — output 909. When i = 1, the full mirror 1234567890987654321 appears.

📈 Custom Max Digit

Read the max digit with scanf and generalize loop bounds.

Example 2 — User Input Max Digit

Read max with scanf("%d", &max); outer loop runs from max + 1 down to 1.

c
#include <stdio.h>

int main() {
    int max;
    int i, j, k;

    printf("Enter max digit (1-9): ");
    scanf("%d", &max);
    if (max < 1) max = 1;
    if (max > 9) max = 9;

    for (i = max + 1; i >= 1; --i) {
        for (j = i; j <= max; ++j)
            printf("%d", j);

        printf("0");

        for (k = max; k >= i; --k)
            printf("%d", k);

        printf("\n");
    }

    return 0;
}

How It Works

Replace hard-coded 9 and 10 with max and max + 1. Clamp input to 1..9 so loop bounds stay valid. Non-numeric input leaves max unset if you ignore scanf’s return value — always check it in safer labs.

⚡ Spaced Output

Add a space between digits for easier reading on wide rows.

Example 3 — Spaced Digits

Keep max = 9 but print each digit followed by a space in both loops.

c
#include <stdio.h>

int main() {
    int max = 9;
    int i, j, k;

    for (i = max + 1; i >= 1; --i) {
        for (j = i; j <= max; ++j)
            printf("%d ", j);

        printf("0 ");

        for (k = max; k >= i; --k)
            printf("%d ", k);

        printf("\n");
    }

    return 0;
}

How It Works

Only the print statements change — printf("%d ", j) and printf("%d ", k). The three-loop structure and 0 center stay the same as Example 1.

🧠 How the Algorithm Prints Rows

1

Set up

#include <stdio.h> brings in printf / scanf. Set loop variables i, j, k with max digit 9.

Setup
2

Outer loop walks rows

for (i = 10; i >= 1; i--) — descending outer loop; one row per iteration.

Row
3

Ascending inner loop (j)

for (j = i; j < 10; j++) — prints digits i..9 (left half).

Ascend
4

Print center zero

printf("0") — fixed center between both inner loops.

Center
5

Descending inner loop (k)

for (k = 9; k >= i; k--) — prints digits 9..i, then printf("\n").

Mirror
=

0-centered mirror complete

Rows grow toward 1234567890987654321O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — max = 9 (selected rows)

Trace selected outer-loop values of i, the left half, center, right half, and full row output.

iLeft (j)CenterRight (k)Row output
10(none)0(none)0
9909909
88, 909, 889098
22..909..223456789098765432
11..909..11234567890987654321

When i = max + 1, both inner loops are empty — only 0 prints. Each row grows as i decreases.

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Teaching Nested Loops

Clearest visual proof that outer and inner bounds interact.

Example: change j < 10 to j <= 10 and watch the left half grow differently.

2. Pattern Series Base

Foundation for inverted, pyramid, diamond, and hollow variants.

Example: continue to Program 29 for a spaced mirror with alignment gaps.

3. Console Formatting Drills

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

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

4. Spaced formatting

Add spaces between digits once the two-loop structure works.

Example: use printf("%d ", j) in both inner loops.

5. Complexity Intuition

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

Example: count printed digits for max = 5 — grows toward a full mirror row of 11 digits.

6. Input Validation Labs

Pair the pattern with scanf return checks and positive-row checks.

Example: reject max <= 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.

Advantages

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

  1. 1. Instant Visual Feedback

    Wrong bounds show up immediately as a broken staircase.

  2. 2. Minimal Concepts

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

  3. 3. Easy to Extend

    Invert, center, hollow, or change the fill character with small edits.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: trace i, j, and k on paper for max = 3 before coding — when i = 4 only 0 prints.

Usage Tips

Small habits that keep number-pattern code clean.

  1. 1. Keep Bounds Consistent

    Use j < max + 1 or j <= max on the left, and k >= i on the right — match hard-coded 9 and 10 when generalizing.

  2. 2. Prefer scanf

    Check the return value so bad input does not leave max uninitialized.

  3. 3. Keep printf("\n") Outside

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

  4. 4. Trace i, j, and k on Paper

    Mark the ascending half and mirror half for each row before coding.

  5. 5. Dry-Run max = 3

    Trace i = 4..1 on paper before coding the full max = 9 demo.

Pro Tip: if the output is a vertical list of single digits per line, you almost certainly put printf("\n") inside the inner loop.

Common Pitfalls

Mistakes that commonly break 0-centered mirror patterns.

  1. 1. Newline Inside the Inner Loop

    Each digit lands on its own line — you get a column, not a triangle.

    → Use printf("%d", j), printf("0"), or printf("%d", k); printf("\n") only after all three parts.

  2. 2. Wrong Outer Loop Start

    Starting at i = max skips the single-0 first row.

    → Start the outer loop at max + 1 so the first row prints only 0.

  3. 3. Forgetting the Center Zero

    Without printf("0"), rows concatenate digits with no fixed center.

    → Print 0 between the ascending and descending inner loops.

  4. 4. Mismatched j and k Bounds

    Using j <= max on the left but k > i on the right breaks symmetry.

    → Mirror bounds: left j = i..max, right k = max..i.

  5. 5. Unchecked scanf

    Letters or empty input leave max uninitialized.

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

Edge Cases

Check these inputs before calling the solution done.

i = max+1

First row only 0

Both inner loops empty — output is just 0.

max = 0

Invalid max

Clamp or reject — loops need a positive max digit.

max > 9

Out of range

Single-digit pattern — clamp to 9 for console demos.

max = 1

Smallest mirror

Two rows: 0 and 101.

Bad input

Non-numeric scanf input

Unchecked scanf leaves max unset — check the return value.

Large max

Large max digit

Output grows as max² digits — fine for labs, noisy beyond 9.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Palindrome triangle

  • Two inner loops without a zero center
  • Review Program 27

2. Spaced mirror

  • Mirror with alignment spaces between halves
  • Continue with Program 29

3. Custom center char

  • Replace 0 with * or #
  • Same three-loop structure

4. Smaller max demo

  • Run with max = 4 and trace every row
  • Compare with Example 2 output

Notes

  • Center rule. Print 0 between the ascending loop (j) and descending loop (k) on every row.
  • printf stays on the line; printf("\n") advances — mix them carefully.
  • Validate max in 1..9 for interactive programs; max = 1 gives rows 0 and 101.
  • Add spaces with printf("%d ", j) in both loops for easier reading on wide rows.

Quick Takeaway: outer loop i = max+1..1, ascending j = i..max, printf("0"), descending k = max..i, then printf("\n").

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–3)O(n²)O(1)
Spaced output (Example 3)O(n²)O(1)
Wrap Up

🎉 Conclusion

The 0-centered descending mirror pattern is a compact lesson in three coordinated loops: print ascending i..max, a fixed 0, then descending max..i. Master the fixed-max = 9 version, then try custom max and spaced output.

Practice the three examples above, then continue to Program 29 for the spaced mirror number pattern.

Start the outer loop at max + 1 for the single-0 first row — validate max when reading from the console.

💡 Best Practices

✅ Do

  • Use for (i = max + 1; i >= 1; i--) in the outer loop
  • Ascend with for (j = i; j <= max; j++)
  • Print printf("0") between inner loops
  • Mirror with for (k = max; k >= i; k--)
  • Check scanf return value and clamp max to 1..9

❌ Don’t

  • Call printf("\n") inside either inner loop
  • Start outer loop at max instead of max + 1
  • Forget the center 0 between loops
  • Use mismatched bounds on j and k
  • Ignore bad console input in user-facing demos
  • Skip the i = max + 1 edge case

Key Takeaways

Knowledge Unlocked

Five things to remember about this 0-centered pattern

Print the pattern the beginner-friendly way.

5
Core concepts
02

j = i..max

Left half

Code
+ 03

printf("0")

Center

Code
04

k = max..i

Right half

Shape
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

printf("0") sits between the ascending and descending loops, creating a fixed center on every row.
When i = 10, the j loop (j = i; j < 10) never runs and the k loop (k = 9; k >= 10) never runs — only 0 is printed.
With max digit 9, i runs from max+1 down to 1. When i = 10 both side loops are empty, giving the single 0 row.
Program 27 mirrors 1..i on each row. Program 28 uses a fixed 0 center and grows digits toward 9 on both sides as i decreases.
Replace 9 with max and start i at max+1 — see Example 2.
Use printf("%d ", j) and printf("%d ", k) in the loops instead of printf("%d", j).
O(n²) for max digit n because each row prints O(n) digits and there are O(n) rows.
Check scanf return value and clamp max to 1..9: if (scanf("%d", &max) != 1) handle bad input.
Two rows: 0 and 101 — the smallest non-trivial mirror with a zero center.

Did you Know? 🔊

This pattern prints ascending digits from i to 9, a fixed 0 in the center, then descending digits from 9 down to i. As i decreases, each row grows into the long mirror 1234567890987654321.

Continue to Program 29

Move on to the spaced mirror number pattern in the C number-pattern series.

Program 29 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.

12 people found this page helpful