Shape Rule
0 at center
Each row is ascending digits, 0, then descending digits — a mirror around zero.

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.
0 at center
Each row is ascending digits, 0, then descending digits — a mirror around zero.
i = 10..1
for (i = 10; i >= 1; i--) — descending outer loop grows each row.
i..9
for (j = i; j < 10; j++) prints the ascending left half.
9..i
for (k = 9; k >= i; k--) mirrors digits after the zero.
max 3–9
Pick a max digit and draw the 0-centered mirror pattern in the browser.
Complexity
Total prints grow as n² for max digit n.
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.
It introduces three coordinated loops with a fixed center — a step up from Program 27’s two-loop palindrome.
Console.Write("0") between both inner loops.
Ascending digits grow as i decreases.
Descending mirror completes each row.
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 WriteLine().
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.
// max = 9 (conceptual shape)
// 0
// 909
// 89098
// 7890987
// ...
// 1234567890987654321 | Item | Type | Description |
|---|---|---|
max | int | Highest digit on each side — typically 9; outer loop starts at max + 1. |
i | int | Descending outer loop — controls how many digits appear on each side. |
j | int | Ascending loop — prints i..max (left half). |
k | int | Descending loop — prints max..i (right half). |
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 | Idea | Best for |
|---|---|---|
| Three loops + 0 | 0, 909, 89098, … | Learning and interviews |
| Custom max digit | int max = Convert.ToInt32(...) | Flexible console programs |
| Spaced output | Console.Write(j + " ") | Easier reading for wide rows |
| Goal | Pattern |
|---|---|
| Walk rows | for (i = 10; i >= 1; i--) |
| Left half | for (j = i; j < 10; j++) Console.Write(j); |
| Center zero | Console.Write("0"); |
| Right half | for (k = 9; k >= i; k--) Console.Write(k); |
| End the row | Console.WriteLine(); |
| Custom max | for (i = max + 1; i >= 1; i--) with j <= max, k >= i |
Same 0-centered mirror — different ways to control max digit and formatting.
i = max+1..1Descending — grows each row
j = i..maxAscending digits
Write("0")Fixed zero between loops
i = max+1First row prints only 0
Reach for this pattern when teaching three coordinated loops with a fixed center character.
Natural follow-up after Program 27 — introduces a fixed 0 center and descending outer loop.
Outer/inner bound practice with an immediate visual check.
Combine loops with ReadLine for a flexible row count.
Compare Program 27 (palindrome triangle) and Program 29 (spaced mirror) next.
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.
Choose a max digit between 3 and 9 and draw the 0-centered mirror pattern in the browser.
Three complete C# programs — fixed rows, user input, and spaced output variant. Click View Output to reveal sample console results.
Print ten rows of the 0-centered mirror with max digit 9 and outer loop i = 10..1.
max = 9Hard-coded max digit — ideal for first demos and screenshots.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int i, j, k;
for (i = 10; i >= 1; i--)
{
for (j = i; j < 10; j++)
Console.Write(j);
Console.Write("0");
for (k = 9; k >= i; k--)
Console.Write(k);
Console.WriteLine();
}
}
}
} 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.
Read the max digit from the console and generalize loop bounds.
Read max from the console; outer loop runs from max + 1 down to 1.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter max digit (1-9): ");
int max = Convert.ToInt32(Console.ReadLine());
if (max < 1) max = 1;
if (max > 9) max = 9;
for (int i = max + 1; i >= 1; i--)
{
for (int j = i; j <= max; j++)
Console.Write(j);
Console.Write("0");
for (int k = max; k >= i; k--)
Console.Write(k);
Console.WriteLine();
}
}
}
} Replace hard-coded 9 and 10 with max and max + 1. Clamp input to 1..9 so loop bounds stay valid.
Add a space between digits for easier reading on wide rows.
Keep max = 9 but print each digit followed by a space in both loops.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int max = 9;
for (int i = max + 1; i >= 1; i--)
{
for (int j = i; j <= max; j++)
Console.Write(j + " ");
Console.Write("0 ");
for (int k = max; k >= i; k--)
Console.Write(k + " ");
Console.WriteLine();
}
}
}
} Only the print statements change — Console.Write(j + " ") and Console.Write(k + " "). The three-loop structure and 0 center stay the same as Example 1.
using System; brings in Console. Set loop variables i, j, k with max digit 9.
for (i = 10; i >= 1; i--) — descending outer loop; one row per iteration.
for (j = i; j < 10; j++) — prints digits i..9 (left half).
Console.Write("0") — fixed center between both inner loops.
for (k = 9; k >= i; k--) — prints digits 9..i, then WriteLine().
Rows grow toward 1234567890987654321 — O(n²) time, O(1) extra memory.
max = 9 (selected rows)Trace selected outer-loop values of i, the left half, center, right half, and full row output.
i | Left (j) | Center | Right (k) | Row output |
|---|---|---|---|---|
10 | (none) | 0 | (none) | 0 |
9 | 9 | 0 | 9 | 909 |
8 | 8, 9 | 0 | 9, 8 | 89098 |
2 | 2..9 | 0 | 9..2 | 23456789098765432 |
1 | 1..9 | 0 | 9..1 | 1234567890987654321 |
When i = max + 1, both inner loops are empty — only 0 prints. Each row grows as i decreases.
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 j < 10 to j <= 10 and watch the left half grow differently.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: continue to Program 29 for a spaced mirror with alignment gaps.
Practice Write vs WriteLine without complex math.
Example: put WriteLine inside the inner loop by mistake.
Add spaces between digits once the two-loop structure works.
Example: use Console.Write(j + " ") in both inner loops.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for max = 5 — grows toward a full mirror row of 11 digits.
Pair the pattern with TryParse 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.
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, j, and k on paper for max = 3 before coding — when i = 4 only 0 prints.
Small habits that keep number-pattern code clean.
Use j < max + 1 or j <= max on the left, and k >= i on the right — match hard-coded 9 and 10 when generalizing.
TryParseAvoid crashes when the user types letters instead of a number.
Only call WriteLine() after the inner loop finishes the row.
Mark the ascending half and mirror half for each row before coding.
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 WriteLine inside the inner loop.
Mistakes that commonly break 0-centered mirror patterns.
Each digit lands on its own line — you get a column, not a triangle.
→ Use Write(j), Write("0"), or Write(k); WriteLine only after all three parts.
Starting at i = max skips the single-0 first row.
→ Start the outer loop at max + 1 so the first row prints only 0.
Without Console.Write("0"), rows concatenate digits with no fixed center.
→ Print 0 between the ascending and descending inner loops.
Using j <= max on the left but k > i on the right breaks symmetry.
→ Mirror bounds: left j = i..max, right k = max..i.
Letters or empty input throw FormatException.
→ Prefer int.TryParse and re-prompt on failure.
Check these inputs before calling the solution done.
Both inner loops empty — output is just 0.
Clamp or reject — loops need a positive max digit.
Single-digit pattern — clamp to 9 for console demos.
Two rows: 0 and 101.
Convert.ToInt32 throws — use TryParse.
Output grows as max² digits — fine for labs, noisy beyond 9.
Try these variations to lock in the pattern.
0 with * or #max = 4 and trace every row0 between the ascending loop (j) and descending loop (k) on every row.Console.Write stays on the line; WriteLine advances — mix them carefully.max in 1..9 for interactive programs; max = 1 gives rows 0 and 101.Console.Write(j + " ") in both loops for easier reading on wide rows.Quick Takeaway: outer loop i = max+1..1, ascending j = i..max, Write("0"), descending k = max..i, then WriteLine().
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–3) | O(n²) | O(1) |
| Spaced output (Example 3) | O(n²) | O(1) |
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.
for (i = max + 1; i >= 1; i--) in the outer loopfor (j = i; j <= max; j++)Console.Write("0") between inner loopsfor (k = max; k >= i; k--)int.TryParse and clamp max to 1..9WriteLine inside either inner loopmax instead of max + 10 between loopsj and ki = max + 1 edge casePrint the pattern the beginner-friendly way.
j..max, 0, max..i
DefinitionLeft half
CodeCenter
CodeRight half
ShapeO(n²) time
AnalysisThis 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.
Move on to the spaced mirror number pattern in the C# number-pattern series.
12 people found this page helpful