C# program to print left and right-aligned pattern of asterisks

Pattern -1

    *
    * * 
    * * *
    * * * *
    * * * * *
    ----- till n row.

Program

using System;
using System.Collections;

namespace ConsoleApplication1
{
 
    class Program
    {
        static void Main()
        {
            int inner = 0;
            int outer = 0;
            
            int n = 0;

            Console.Write("Enter Value of N : ");
            n = Convert.ToInt32(Console.ReadLine());

            for (outer = 1; outer <= n; outer++)
            {
                for (inner = 0; inner < outer; inner++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}

Pattern -2

        *
       * *
    *  * *
  * *  * *
* * *  * *   
----- till n row.

Program

using System;
using System.Collections;
namespace ConsoleApplication1
{ 
   class Program
    {
        static void Main()
        {
            int inner = 0;
            int outer = 0;
            int space = 0;
            int n = 0;

            Console.Write("Enter Value of N : ");
            n = Convert.ToInt32(Console.ReadLine());

            for (outer = 1; outer <= n; outer++)
            {
                for (space = n; space > outer; space--)
                {
                    Console.Write(" ");
                }
                for (inner = 0; inner < outer; inner++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}

Leave a Comment

error: Alert: Content is protected!!