# C# Program to Find the Perimeter of Circle and Rectangle

This is a C# Program to calculate primeter of circle and rectangle.

Problem Description

This C# Program Calculates Perimeter of Circle and Rectangle.

Problem Solution

Here length and breadth of the rectangle and radius of the circle is also obtained and perimeter of circle and rectangle is calculated.

Program/Source Code

Here is source code of the C# Program to Calculate Perimeter of Circle and Rectangle. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

```/*
* C# Program to Calculate Perimeter of Circle and Rectangle
*/
using System;
using System.IO;
class program
{
public static void Main()
{

double l,b,r,per_rect,per_cir;
double PI = 3.14;
Console.WriteLine("Enter the Length and Breadth : ");
l = Convert.ToDouble(Console.ReadLine());
b = Convert.ToDouble(Console.ReadLine());
per_rect = 2 * (l + b);
Console.WriteLine("Enter the radius of the circle : ");
r = Convert.ToDouble(Console.ReadLine());
per_cir = 2 * PI * r;
Console.WriteLine("Perimeter of Rectangle : {0}", per_rect);
Console.WriteLine("Perimeter of Circle : {0}", per_cir);
Console.Read();
}
}```
Program Explanation

In this C# program, library function defined in <math.h> header file is used. We are reading the length and breadth using ‘l’ and ‘b’ variables respectively. To compute the perimeter of a rectangle the following formula is used

advertisement
advertisement

perimeter = 2 * (l + b).

We are reading the radius of the circle using ‘r’ variable. To compute the perimeter of circle the formula is used

perimeter = 2 * PI * r

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

where PI = 22/7.

Runtime Test Cases
```
Enter the Length and Breadth :
3
2
Enter the radius of the circle :
4
Perimeter of Rectangle : 10
Perimeter of Circle : 25.12```

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

advertisement
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.