Objective
Write a C# program that asks for a number, width, and height, and displays a rectangle of that width and height, using that number for the inner symbol, as shown in the example below:
Enter a number: 4
Enter the desired width: 3
Enter the desired height: 5
444
444
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()
{
// Prompt the user to enter the number to display inside the rectangle
Console.Write("Enter a number: ");
int number = int.Parse(Console.ReadLine()); // Reading the number entered by the user
// Prompt the user to enter the desired width of the rectangle
Console.Write("Enter the desired width: ");
int width = int.Parse(Console.ReadLine()); // Reading the width entered by the user
// Prompt the user to enter the desired height of the rectangle
Console.Write("Enter the desired height: ");
int height = int.Parse(Console.ReadLine()); // Reading the height entered by the user
// Loop to print the rectangle row by row
for (int i = 0; i < height; i++) // Loop runs for the height of the rectangle
{
// Loop to print the number across the width of the rectangle
for (int j = 0; j < width; j++) // Loop runs for the width of the rectangle
{
Console.Write(number); // Display the number at the current position
}
Console.WriteLine(); // Move to the next line after printing one row of the rectangle
}
}
}