Number & Asterisk Mirror Pattern in C#

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Symmetry

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:

Output
1234554321
1234**4321
123****321
12******21
1********1
1

Complete C# Program

Print ascending numbers, then pairs of *, then descending numbers for each row.

C#
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

1

Outer loop shrinks the number range

i goes from 5 down to 1, so each row prints fewer numbers.

Row control
2

Print 1..i

The first inner loop prints ascending numbers from 1 to i.

Left half
3

Print pairs of *

The middle loop prints "**" as many times as needed to expand the center.

Center
4

Print i..1

The last loop prints descending numbers from i down to 1 to mirror the left half.

Right half
=

Perfectly symmetric output

As numbers shrink, the star block grows to keep symmetry.

2

Variation — Custom n

Make the pattern size dynamic by reading n from the console:

C#
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

1

Print 1..i and i..1 to create a mirror.

2

Insert a growing middle section to keep symmetry as the sides shrink.

3

Using ** grows the middle by 2 characters per step.

4

Overall complexity is \(O(n^2)\) for size \(n\).

❓ Frequently Asked Questions

Because the code prints "**" in a loop, so each loop iteration adds two stars.
Yes. Replace "**" with two spaces " " (or any string) to change the center fill.
O(n²) for size n because total printed characters scale with the square of n.

Explore More C# Number Patterns!

Mirror patterns are great practice for combining multiple loops on the same line.

All Number Patterns →
Did you know?

Many symmetric patterns can be built by printing a left half, then a center, then a reversed right half.

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