BASIC STAR PATTERN CODE IN C# LANGUAGE

Abhishek Srivasatava

Total Post:70

Points:350
Posted by  Abhishek Srivasatava
C# 
C#
 475  View(s)
Ratings:
Rate this:
  1. Abhishek Srivasatava

    Post:70

    Points:350
    Basic star pattern code in C# language

    Here is the complete code for each star Pattern in C#

    Pattern 1

    *

    **

    ***

    ****

    *****

    static void Main(string[] args)
            {
                int val = 5;
                int i, j;
                for (i = 0; i <= val; i++)
                {
                    for (j = 0; j <= i;j++)
                    {
                        Console.Write("*");
                    } Console.WriteLine("");
                }
                Console.ReadLine();
            }

    Pattern 2:
            *

          **

        ***

      ****

    *****

    static void Main(string[] args)
            {
     
                       for (int j = 10; j >0;j--)
                {
                    for (int k =j ; k >=0 ;k--)
                    {
                        Console.Write(" ");
                    }
                    for (int l = 0; l <=10-j;l++)
                    {
                        Console.Write("*");
                    }
                        Console.Write("\n");
                }
                Console.ReadLine();
    }

    Pattern 3:
    Even

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

    static void Main(string[] args)
            {
     
                       for (int j = 10; j >0;j--)
                {
                    for (int k =j ; k >=0 ;k--)
                    {
                        Console.Write(" ");
                    }
                    for (int l = 0; l <=10-j;l++)
                    {
                        Console.Write("*");
                    }
                    for (int m = 0; m <=10-j; m++)
                    {
                        Console.Write("*");
                    }
                        Console.Write("\n");
                }
                Console.ReadLine();  
            }

    Pattern 4
    Odd 

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

    static void Main(string[] args)
            {
     
                       for (int j = 10; j >0;j--)
                {
                    for (int k =j ; k >=0 ;k--)
                    {
                        Console.Write(" ");
                    }
                    for (int l = 0; l <=10-j;l++)
                    {
                        Console.Write("*");
                    }
                    for (int m = 0; m < 10-j; m++)
                    {
                        Console.Write("*");
                    }
                        Console.Write("\n");
                }
                Console.ReadLine();  
            }

    Pattern 5
    *****
    ****
    ***
    **
    *

    static void Main(string[] args)
            {
             
                int i, j;
                for (i = 10; i > 0; i--)
                {
                    for (j = 0; j < i;j++)
                    {
                        Console.Write("*");
                    } Console.WriteLine("");
                }
                Console.ReadLine();
            }
     

      Modified On Oct-20-2016 11:41:49 AM
  1. Shikhar S.

    Post:1

    Points:5
    Basic star pattern code in C# language

    Pattern 2 is wrong as per the visual representation desired. I had tried it on the VS2013 compiler.

    The code very close to the visual representation is:
                for (int i = 10; i > 0; i--)
        {
            for (int j = i; j >= i/2; j--)
            {
                Console.Write(" ");
            }
            for (int k = 0; k <= 10 - i; k++)
            {
                Console.Write("*");
            }
            Console.Write("\n");
        }
        Console.ReadLine();

  1. Abhishek Srivasatava

    Post:70

    Points:350
    Basic star pattern code in C# language

    pattern 2  was this:

         *
       **
     ***
    ****

    Thanks for acknowledgement .


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!