Create the Pyramid in C#

How To write a program to display Pyramid in c#


using System;

namespace Test_Application
{
    class Program
    {
        static void Main(string[] args)
        {
            int val = 4, x,y;
            for (int i = 1; i <= val; i++)
            {
                for (x = 1; x <= (val - i); x++)
                {
                    Console.Write(" "); //add the space.
                }
                for (y = 1; y <= i; y++) //increase the value
                {
                    Console.Write('*');
                }
                for (y = (i-1); y >= 1; y--)  //decrease the value
                {
                    Console.Write('*');
                }
                Console.WriteLine();
            }
            Console.Read();
         
        }
    }

}

Output:-

      *
    ***
  *****
*******


Share this

Previous
Next Post »