# C# program to calculate the perimeter of Rectangle

Here, we are going to learn how to calculate the perimeter of Rectangle in C#?
Submitted by Nidhi, on October 11, 2020

Here, we will calculate the perimeter of the Rectangle using the below formula.

```perimeter = 2 * (length + width);
```

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: ");

Console.Write("Enter the value of width: ");

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);
```

What's New (MCQs)

Top Interview Coding Problems/Challenges!

IncludeHelp's Blogs

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates