Q:

C# program to calculate the perimeter of Rectangle

belongs to collection: C# Basic Programs | basics

0

C# program to calculate the perimeter of Rectangle

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to calculate the perimeter of the Rectangle is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to calculate the perimeter of the 
//rectangle in C#

using System;

class Rectangle
{
    public static int Main()
    {
        float length    = 0.0F;
        float width   = 0.0F;
        float perimeter = 0.0F;

        Console.Write("Enter the value of length: ");
        length = float.Parse(Console.ReadLine());

        Console.Write("Enter the value of width: ");
        width = float.Parse(Console.ReadLine());

        perimeter = 2 * (length + width);

        Console.WriteLine("Perimeter of rectangle: "+perimeter);
        return 0;
    }
}

Output:

Enter the value of length: 5
Enter the value of width: 7
Perimeter of rectangle: 24
Press any key to continue . . .

Explanation:

Here, we created a class Rectangle that contains a method Main(). The Main() method is the entry point for the program. Here we read the value of length and width and calculate the perimeter of the Rectangle using the below formula, and then print the result on the console screen.

perimeter = 2 * (length + width);

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to calculate the NCR... >>
<< C# program to calculate the perimeter of Circle...