C# Console Application. A simple program to calculate the area and perimeter of a square, using the height.
Variables are defined in the first row. In the next lines, values are assigned to these variables.
In the last line we print the Area and Perimeter of rectangle to the screen.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 |
static void Main(string[] args) { int squareheight,area,perimeter; Console.Write("What is the height of your square? :"); squareheight = Convert.ToInt32(Console.ReadLine()); area = squareheight * squareheight; perimeter = 4 * squareheight; Console.WriteLine("Area : {0}\nPerimeter : {1}",area,perimeter); // "\n"--> new line Console.ReadKey(); } |
Output: