Mirrored Number Pattern in C#

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

What You’ll Learn

How to print a mirrored number pattern where the left side increases (1..i) and the right side decreases (i..1). Spaces in the middle keep the mirror aligned.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
1        1
12      21
123    321
1234  4321
1234554321
1

Complete C# Program

This follows the reference approach exactly: one loop prints the left half (or spaces), and another loop prints the right half (or spaces).

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, k;

            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= 5; j++)
                {
                    if (j <= i)
                        Console.Write(j);
                    else
                        Console.Write(" ");
                }

                for (k = 5; k >= 1; k--)
                {
                    if (k > i)
                        Console.Write(" ");
                    else
                        Console.Write(k);
                }

                Console.WriteLine();
            }
        }
    }
}
2

Variation — User Input rows

Same idea, but make the height configurable:

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter rows: ");
            int rows = Convert.ToInt32(Console.ReadLine());
            if (rows < 1) return;

            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= rows; j++)
                    Console.Write((j <= i) ? j.ToString() : " ");

                for (int k = rows; k >= 1; k--)
                    Console.Write((k > i) ? " " : k.ToString());

                Console.WriteLine();
            }
        }
    }
}

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