.Net Practical 5

Practical : 5
Subject : .Net

Aim : Write C# code to display the asterisk pattern as shown below:
*****
  ****
    ***
      **
        *


Source Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace pr008
{
    class pat1
    {
        static void Main(string[] ar)
        {
            int i, j, k;
            Console.Write("Enter number : ");
            int n = Convert.ToInt32(Console.ReadLine());
            for (i = 0; i < n; i++)
            {
                for(j=0;j<=i;j++)
                {
                    Console.Write(" ");
                }
                for(k=n;k>i;k--)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}
Output :

Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment