Number-Star Diamond Pattern in C#

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

What You’ll Learn

How to print a diamond-like pattern that alternates between the row number and * characters:

1, 2*2, 3*3*3, ... then back down to 1.

⭐ Pattern Output

For n = 5, the pattern looks like this:

Output
1
2*2
3*3*3
4*4*4*4
5*5*5*5*5
4*4*4*4
3*3*3
2*2
1
1

Complete C# Program

This is the exact reference approach: print the top half with i = 1..5, then print the bottom half with i = 4..1. Use j % 2 to alternate.

C#
using System;

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

            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j < i * 2; j++)
                {
                    if (j % 2 == 0)
                        Console.Write("*");
                    else
                        Console.Write(i);
                }
                Console.WriteLine();
            }

            for (i = 4; i >= 1; i--)
            {
                for (j = 1; j < i * 2; j++)
                {
                    if (j % 2 == 0)
                        Console.Write("*");
                    else
                        Console.Write(i);
                }
                Console.WriteLine();
            }
        }
    }
}
2

Variation — User Input n

Make the height configurable:

C#
using System;

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

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j < i * 2; j++)
                    Console.Write((j % 2 == 0) ? "*" : i.ToString());
                Console.WriteLine();
            }

            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = 1; j < i * 2; j++)
                    Console.Write((j % 2 == 0) ? "*" : i.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