C#: Print a number four times in separate rows
Repeat Number in Rows
Write a C# program that takes a number as input and displays it four times in a row (separated by blank spaces), and then four times in the next row, with no separation. You should do it twice: Use the console. Write and use {0}.

Sample Solution:
C# Sharp Code:
using System;
// This is the beginning of the Exercise12 class
public class Exercise12
{
// This is the main method where the program execution starts
public static void Main()
{
int num; // Variable to store the digit entered by the user
// Prompting the user to enter a digit
Console.WriteLine("Enter a digit: ");
// Reading the digit entered by the user and converting it to an integer
num = Convert.ToInt32(Console.ReadLine());
// Part A: "num num num num" using Write
Console.Write(num);
Console.Write(" ");
Console.Write(num);
Console.Write(" ");
Console.Write(num);
Console.Write(" ");
Console.Write(num);
Console.WriteLine();
// Part B: "numnumnumnum" using Write
Console.Write(num);
Console.Write(num);
Console.Write(num);
Console.WriteLine(num);
Console.WriteLine();
// Part C: "num num num num" using {0}
Console.WriteLine("{0} {0} {0} {0}", num);
// Part D: "numnumnumnum" using {0}
Console.WriteLine("{0}{0}{0}{0}", num);
}
}
Sample Output:
Enter a digit: 2 2 2 2 2 2222 2 2 2 2 2222
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C# program to take a digit and print it in a pyramid-like pattern using string manipulation.
- Write a C# program to repeat a digit n times in n rows based on user input.
- Write a C# program to display a digit repeated multiple times but only on prime-indexed rows.
- Write a C# program that takes a digit and prints it in alternating rows of spaced and unspaced format.
Go to:
PREV : Print Age Message.
NEXT : Rectangle Pattern with Number.
C# Sharp Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.