Number & Asterisk Mirror Pattern in C#

What You’ll Learn
How to print a mirror number pattern in C# where the digits shrink and the center is filled with a growing block of asterisks.
Example output: 1234554321, 1234**4321, 123****321, 12******21, 1********1.
⭐ Pattern Output
For n = 5, the pattern looks like this:
1234554321
1234**4321
123****321
12******21
1********1Complete C# Program
Print ascending numbers, then pairs of *, then descending numbers for each row.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int i, j, k, m;
for (i = 5; i >= 1; i--)
{
for (j = 1; j <= i; j++)
Console.Write(j);
for (k = i; k < 5; k++)
Console.Write("**");
for (m = i; m >= 1; m--)
Console.Write(m);
Console.WriteLine();
}
}
}
}🧠 How It Works
Outer loop shrinks the number range
i goes from 5 down to 1, so each row prints fewer numbers.
Print 1..i
The first inner loop prints ascending numbers from 1 to i.
Print pairs of *
The middle loop prints "**" as many times as needed to expand the center.
Print i..1
The last loop prints descending numbers from i down to 1 to mirror the left half.
Perfectly symmetric output
As numbers shrink, the star block grows to keep symmetry.
Variation — Custom n
Make the pattern size dynamic by reading n from the console:
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter n: ");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
Console.Write(j);
for (int k = i; k < n; k++)
Console.Write("**");
for (int m = i; m >= 1; m--)
Console.Write(m);
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Use a single
*instead of**to change the center width growth - Replace
*with another symbol (like#) - Add spaces between digits if you want a wider pattern
Avoid
- Forgetting the descending loop (you’ll lose the mirror effect)
- Mixing up loop bounds (symmetry relies on correct limits)
Key Takeaways
Print 1..i and i..1 to create a mirror.
Insert a growing middle section to keep symmetry as the sides shrink.
Using ** grows the middle by 2 characters per step.
Overall complexity is \(O(n^2)\) for size \(n\).
❓ Frequently Asked Questions
"**" in a loop, so each loop iteration adds two stars."**" with two spaces " " (or any string) to change the center fill.Explore More C# Number Patterns!
Mirror patterns are great practice for combining multiple loops on the same line.
Many symmetric patterns can be built by printing a left half, then a center, then a reversed right half.
12 people found this page helpful
