How to Find the Perimeter of a Rectangle in C# Program
ADVERTISEMENTS
How to find the perimeter of a rectangle in C# program.
In this article, you will learn how to find the perimeter of a rectangle in C# program.
Example
Enter the length & width of the rectangle::
9
8
The Perimeter of rectangle = 34 units
You should have knowledge of the following topics in C# programming to understand this program:
- C# Oops Concepts
- C# System Library
Source Code
// How to Find the Perimeter of a Rectangle in C# Program
using System;
public class W3CW {
static public void Main (string[] args) {
Console.WriteLine("Enter the length & width of the rectangle::\n");
float l=Convert.ToInt32(Console.ReadLine());
float w=Convert.ToInt32(Console.ReadLine());
// It will calculate the perimeter of the rectangle
float p = 2 * (l + w);
// It will print the final output
Console.WriteLine("The Perimeter of rectangle = "+p+" units");
}
}
Output
Enter the length & width of the rectangle::
9
8
The Perimeter of rectangle = 34 units
Explanation
In this program, we have taken two inputs from the user rectangle's width 9
and rectangle's height 8
.
Then used the standard formula P = 2(l + w)
to calculate the perimeter of a rectangle then it will return the 34 units
the perimeter of the rectangle.