Diamond patterns program in C#

This console program show how to print diamond pattern in C#.

Source code - Diamond patterns program in Console(C#).


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace diamondpatterns
    {
        class Program
        {
            static void Main(string[] args)
            {
            Console.WriteLine("PROGRAM FOR DISPLAYING PATTERN OF *.");
            Console.Write("ENTER THE MAXIMUM NUMBER OF *: ");
            int n = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("\nHERE IS THE DIAMOND OF STARS.\n");

            for (int i = 1; i <= n; i++)
            {
                for (int j = 0; j < (n - i); j++)
                    Console.Write(" ");
                for (int j = 1; j <= i; j++)
                    Console.Write("*");
                for (int k = 1; k < i; k++)
                    Console.Write("*");
                Console.WriteLine();
            }

            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = 0; j < (n - i); j++)
                    Console.Write(" ");
                for (int j = 1; j <= i; j++)
                    Console.Write("*");
                for (int k = 1; k < i; k++)
                    Console.Write("*");
                Console.WriteLine();
            }
               Console.ReadLine();
            }
        }
    }	
	

Output

	
   PROGRAM FOR DISPLAYING PATTERN OF *.
   ENTER THE MAXIMUM NUMBER OF *: 5
          
   HERE IS THE DIAMOND OF STARS.
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *
      * * * * * * *
        * * * * *
          * * *
            *
           
Advertisement here

Share this Page.