Pattern Program In C# (Part – 1)

This article helps to create a star pattern in C# console application.

1.

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

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

2.

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

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

3.

1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321

static void Main(string[] args)
      {
          int num, space;

          while (true)
          {
              Console.Write("Enter a number between 1 to 9 : ");

              num = Convert.ToInt32(Console.ReadLine());

              space = num - 1;

              for (int i = 1; i <= num; i++)
              {
                  for (space = 1; space <= (num - i); space++)
                  {
                      Console.Write(" ");
                  }

                  for (int j = 1; j <= i; j++)
                  {
                      Console.Write(j);
                  }

                  for (int k = (i - 1); k >= 1; k--)
                  {
                      Console.Write(k);
                  }

                  Console.WriteLine();

              }
          }
      }

4.

12345
1234
123
12
1

1
12
123
1234
12345

static void Main(string[] args)
        {
            Console.Write("Enter a number: ");
            int n = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            for (int i = n; i >= 0; i--)
            {
                for (int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= i; j++)
                    Console.Write(j.ToString());
                Console.WriteLine();
            }

            Console.ReadLine();

        }

5.

1******
12*****
123****
1234***
12345**
123456*
1234567

static void Main(string[] args)
        {
            int i, j, s;

            for (i = 1; i <= 7; i++)
            {
                for (j = 1; j <= i; ++j)
                    Console.Write(j);

                for (s = 7 - i; s >= 1; s--)
                    Console.Write("*");

                Console.Write("\n");
            }

            Console.ReadLine();

        }

 

 

 

2 Comments

  1. kashyap

    I want more patterns

    0
    0
    Reply
    1. ok. I will add more

      0
      0
      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories