Square Learn programming C#

Lesson:

Flow Control


Exercise:

Square


Objetive:

Write a C# program that prompts the user to enter a number and a width, and displays a square of that width, using that number for the inner symbol, as shown in this example:

Enter a number: 4
Enter the desired width: 3

444
444
444


Code:

using System;
public class exercise34
{
    public static void Main()
    {
        int n;     // User entered data
        int row, column;   // For loops

        Console.Write("Enter a number: ");
        n = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter the desired: ");
        width = Convert.ToInt32(Console.ReadLine());

        for (row = 0; row; row++)
        {
            for (column = 0; column; column++)
                Console.Write(n);

            Console.WriteLine();
        }
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.