Objective
Write a C# program to ask the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that digit. For example:
Enter a digit: 3
333
3 3
3 3
3 3
333
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()
{
int digit; // Declaring a variable to store the digit entered by the user
// Asking the user to enter a digit and reading the input
Console.Write("Enter a digit: ");
digit = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer
// Printing the top row of the rectangle with the digit repeated three times
Console.WriteLine("{0}{0}{0}", digit); // Printing the digit three times in the first row
// Printing the middle rows of the rectangle, each with the digit followed by a space and then the digit again
for (int i = 0; i < 3; i++) // Loop to print three rows
{
Console.WriteLine("{0} {0}", digit); // Printing the digit with a space between them
}
// Printing the bottom row of the rectangle with the digit repeated three times
Console.WriteLine("{0}{0}{0}", digit); // Printing the digit three times in the last row
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
This C# exercise teaches you how to perform temperature unit conversions. The program prompts the user to input a temperature in Celsius degrees and then converts it ...
This exercise is an excellent way to get started with programming in C#. In this program, you will learn how to print a message on the screen using C#. The program wi...
This exercise is a great way to practice basic arithmetic operations in C#. In this program, you will learn how to perform an addition operation between two numbers, 12 and ...
This exercise is a great opportunity to practice the division operation in C#. In this program, you will learn how to divide two numbers, in this case, 24 and 5, and ...
This exercise is perfect for learning how to perform complex arithmetic operations in C#. In this program, you will be asked to solve several mathematical operations using d...
This exercise is perfect for learning how to perform a multiplication in C# with numbers entered by the user. In this program, the user will be asked to input two numbers, a...