Objective
Write a C# program to ask the user for a number and display it four times in a row, separated with blank spaces, and then four times in the next row, with no separation. You must do it two times: first using Console.Write and then using {0}.
Example:
Enter a number: 3
3 3 3 3
3333
3 3 3 3
3333
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to use Console functionalities
// Main class of the program
class Program
{
// Main method where the program execution begins
static void Main()
{
// Declaring a variable to store the number entered by the user
int number;
// Asking the user to enter a number and reading the input
Console.Write("Enter a number: ");
number = Convert.ToInt32(Console.ReadLine());
// Using Console.Write to display the number four times in a row, separated by blank spaces
Console.WriteLine(); // Adding a newline before the first output
Console.Write(number + " " + number + " " + number + " " + number); // Printing the number with spaces
Console.WriteLine(); // Adding a newline after the first output
// Using Console.Write to display the number four times in the next row, with no separation
Console.Write(number.ToString() + number.ToString() + number.ToString() + number.ToString()); // Printing the number without spaces
Console.WriteLine(); // Adding a newline after the second output
// Using {0} formatting to display the number four times in a row, separated by blank spaces
Console.WriteLine("{0} {0} {0} {0}", number); // Printing the number with spaces
// Using {0} formatting to display the number four times in the next row, with no separation
Console.WriteLine("{0}{0}{0}{0}", number); // Printing the number without spaces
}
}