Search This Blog

Sunday, 13 September 2015

Pyramid program in C# (Type 4)

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number: ");
            int num = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= num; i++)
            {
                Console.WriteLine("");
                for (int j = num; j >= i; j--)
                {
                    Console.Write("*");
                }
                if (i > 1)
                {
                    for (int k = 1; k <= i + 1; k++)
                    {
                        Console.Write(" ");
                    }
                    for (int l = 1; l <= i - 1; l++)
                    {
                        Console.Write(" ");
                    }
                }
                for (int m = num; m >= i; m--)
                {
                    Console.Write("*");
                }
            }
            Console.ReadKey();
        }
    }
}

Output:

Enter the number: 5

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

No comments:

Post a Comment