Search This Blog

Sunday, 13 September 2015

Pyramid program in C# (Type 5)

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 5; i >= 1; i--)
            {
                Console.WriteLine("");
                for (int j = 5; j >= i; j--)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i; k++)
                {
                    Console.Write("*");                  
                }
                if (i >= 2)
                {
                    for (int l = 1; l <= i - 1; l++)
                    {
                        Console.Write("*");
                    }
                }
            }
            Console.WriteLine("");
            Console.ReadKey();
        }
    }
}


Output:

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

No comments:

Post a Comment