Home »
.Net »
C# Programs
C# - Calculate the Area of a Cone
Here, we are going to learn how to calculate the area of a Cone in C#?
By Nidhi Last updated : April 15, 2023
Area of a Cone Formula
Here we will calculate the area of Cone using below formula.
area = Math.PI * radius * (radius + Math.Sqrt(radius * radius + radius * radius));
C# program to calculate the area of a Cone
The source code to calculate the area of a Cone is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# - Calculate the Area of a Cone.
using System;
class Cone
{
public double CalculateArea(double radius, double height)
{
double area = 0.0;
area = Math.PI * radius * (radius + Math.Sqrt(radius * radius + radius * radius));
return area;
}
public static void Main()
{
double area = 0;
double radius = 0;
double height = 0;
Cone C = new Cone();
Console.Write("Enter the radius of a cone: ");
radius = double.Parse(Console.ReadLine());
Console.Write("Enter the height of a cone: ");
height = double.Parse(Console.ReadLine());
area = C.CalculateArea(radius, height);
Console.WriteLine("Area of cone is: "+area);
}
}
Output
Enter the radius of a cone: 10
Enter the height of a cone: 2.2
Area of cone is: 758.447559174816
Press any key to continue . . .
Explanation
Here, we created a class Cone that contains two methods CalculateArea() and Main(). The CalculateArea() method is used to calculate the area of Cone using the below formula and return the calculated area to the calling method.
area = Math.PI * radius * (radius + Math.Sqrt(radius * radius + radius * radius));
In the Main() method, we created three local variables area, radius, and height initialized with 0. Then we created the object of Cone class and read the value of radius and height, after that passed the value of radius and height into CalculateArea() method that will return the calculated area that will be printed on the console screen.
C# Basic Programs »