C# Program to Print the pattern sequence 1 22 333 22 1

C# Program to Print the pattern sequence 1 22 333 22 1 – Learn how to print the pattern of following sequence containing the numbers from 1 to N.

Input Value

num=5

Output Pattern

1
22
333
4444
55555
4444
333
22
1

Example C# Program to Print the pattern sequence 1 22 333 22 1

class Program
{
  static void Main(string[] args)
  {
    // input value for printing the pattern.
    int num=5;

    //below for loop is printing the pattern from 1 to num value

      for (int i = 1; i <= num; i++)
       {
        for (int k = 1; k <= i; k++)
        {
         Console.Write(i);
         if(i==k)
         {
          Console.Write("\n");
         }
        }

       }

//below for loop is printing the pattern from num-1 to 1 value

       for (int i = num - 1; i >= 1; i--)
        {
         for (int k = 1; k <= i; k++)
         {
          Console.Write(i);
          if (i == k)
          {
           Console.Write("\n");
          }
         }

       }
  }
}

Related Posts