C# program to calculate diameter, area and perimeter of a circle has been given below. Suppose, the radius of a circle is r unit, the area and perimeter of that circle would be (pi * r^2) unit^2 and (2 * pi * r) unit, respectively while the diameter would be 2 * r. The approximate value of pi is 3.141592.

For example, if the radius of a circle is 5 cm, then area of the circle would be (pi * 5^2) = 78.54 cm^2 while perimeter and diamerter would be (2 * pi * r) = 31.42 cm and (2 * r) = 10 cm respectively.

The algorithm, pseudocode, and time-complexity of the program have also been covered below.

## 1. Algorithm to calculate diameter, area and perimeter of a circle

1. Take the radius r of a circle as input.

2. Compute d = 2 * r

3. Compute a = pi * r^2

4. Compute p = 2 * pi * r

5. Declare d as the diameter, a as the area and p as the perimeter of that circle.

## 2. Pseudocode to calculate diameter, area and perimeter of a circle

Input : Radius r of a circle

Output : Diameter D, Area A, Perimeter P of the circle

1. Procedure diameterAreaPerimeter(r):

2. D := 2 * r

3. A := pi * r^2

4. P := 2 * pi * r

5. Return D, A, P

6. End Procedure

## 3. Time complexity to calculate diameter, area and perimeter of a circle

Time Complexity: O(1)

## 4. C# Program & Output to calculate diameter, area and perimeter of a circle

Code has been copied
/*************************************
alphabetacoder.com
C# program to calculate the area,
perimeter and diameter of a circle
**************************************/

using System;

namespace AreaPerimeterDiameter {
class Program {
static void Main(string[] args) {
// declare variables
double r, a, p, d;

// take input
Console.Write("Enter the radius of a circle: ");

// calculate area
a = Math.PI * r * r;
// calculate perimeter
p = 2 * Math.PI * r;
// calculate diameter
d = 2 * r;

// display result upto 3 decimal places
Console.Write("Area: " + string.Format("{0:0.000}", a) + "\n");
Console.Write("Perimeter: " + string.Format("{0:0.000}", p) + "\n");
Console.Write("Diameter: " + string.Format("{0:0.000}", d) + "\n");

// wait for user to press any key
}
}
}


Output

Enter the radius of a circle: 6.5

Area: 113.097

Perimeter: 40.841

Diameter: 13.000