Vertical rectangle in c#

Vertical Rectangle Pattern in Console App C#

In this short article, we will learn how to print Vertical Rectangle Pattern in Console App C# using stars.

Sample Code:

public class Program
{
    public static void Main(string[] args)
    {
        int number = 7;

        for (int i = 0; i < number; i++)
        {
            if (i == 0 || i == 6)
            {
                for (int j = 0; j < number; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            if (i >= 1 && i <= 5)
            {
                for (int j = 0; j < number; j++)
                {
                    if (j == 0 || j == 6)
                    {
                        Console.Write("*");
                    }
                    else if (j >= 1 && j <= 5)
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }

    }
}

Leave a Reply

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