Hollow square Learn programming with C# Sharp exercises

Lesson:

Flow Control


Exercise:

Hollow square 113


Objetive:

Write a C# program that asks for a symbol and a width, and displays a hollow square of that width using that symbol for the outer border, as shown in this example:

Enter a symbol: 4
Enter the desired width: 3

444
4 4
444


Code:

using System;
public class exercise39
{
    public static void Main()
    {
        int n;
        int i, j;

        Console.Write("Enter number for the border of the square: ");
        n = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter total: ");
        width = Convert.ToInt32(Console.ReadLine());

        for (i = 0; i; i++)
            Console.Write(n);

        Console.WriteLine();

        for (i = 0; i - 2; i++)
        {
            Console.Write(n);

            for (j = 0; j - 2; j++)
                Console.Write(" ");

            Console.WriteLine(n);
        }

        for (i = 0; i; i++)
            Console.Write(n);

        Console.WriteLine();
    }
}