Users Online

· Guests Online: 22

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Find the Perimeter of Circle and Rectangle

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

 

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

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

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.81 seconds
14,558,317 unique visits