Objective
Write a C# program that prompts the user to enter a number and a width, and displays a square of that width, using that number for the inner symbol, as shown in this example:
Enter a number: 4
Enter the desired width: 3
444
444
444
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
// Prompting the user to enter a number to use as the symbol
Console.Write("Enter a number: ");
int number = int.Parse(Console.ReadLine()); // Reading the user's input and parsing it to an integer
// Prompting the user to enter the desired width of the square
Console.Write("Enter the desired width: ");
int width = int.Parse(Console.ReadLine()); // Reading the user's input and parsing it to an integer
// Outer loop for the rows of the square (height of the square)
for (int i = 0; i < width; i++)
{
// Inner loop for printing the number in each column of the square
for (int j = 0; j < width; j++)
{
// Displaying the number in the current position
Console.Write(number);
}
// Moving to the next line after completing a row
Console.WriteLine();
}
}
}