w3resource

C#: Display a number in rectangle of 3 columns wide and 5 rows tall using that digit


C# Sharp Basic: Exercise-13 with Solution

Write a C# program that takes a number as input and displays a rectangle of 3 columns wide and 5 rows tall using that digit.

C# Sharp Exercises: Display a number in rectangle of 3 columns wide and 5 rows tall using that digit

Sample Solution:

C# Sharp Code:

using System;

// This is the beginning of the Exercise13 class
public class Exercise13
{
    // This is the main method where the program execution starts
    public static void Main()
    {
        int x; // Variable to store the number entered by the user

        // Prompting the user to enter a number
        Console.Write("Enter a number: ");
        // Reading the number entered by the user and converting it to an integer
        x = Convert.ToInt32(Console.ReadLine());

        // Printing the number in a specific pattern
        Console.WriteLine("{0}{0}{0}", x); // Prints the number three times in the same line
        Console.WriteLine("{0} {0}", x); // Prints the number twice with a space in between on each line
        Console.WriteLine("{0} {0}", x); // Prints the number twice with a space in between on each line
        Console.WriteLine("{0} {0}", x); // Prints the number twice with a space in between on each line
        Console.WriteLine("{0}{0}{0}", x); // Prints the number three times in the same line
    }
}

Sample Output:

Enter a number: 5                                                                                             
555  
5 5 
5 5
5 5 
555

Flowchart:

Flowchart: C# Sharp Exercises - Display a number in rectangle of 3 columns wide and 5 rows tall using that digit

C# Sharp Code Editor:

Previous: Write a C# program to that takes a number as input and display 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 two times: Use Console. Write and then use {0}
Next: Write a C# Sharp program to convert from celsius degrees to Kelvin and Fahrenheit.
kelvin = celsius + 273

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.