In this article, we will see how to calculate the area of a circle in C# using method.
The area of a circle can be evaluated using the formula:
Area of circle = pi * r * r //where r is the radius of circle
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class Program { // Method Name --> GetCircleArea() // Return Type ---> double static double GetCircleArea(double radius) { const float pi = 3.14F; double area = pi * radius * radius; return area; } static void Main(string[] args) { Console.Write("Enter Radius : "); double r=Convert.ToDouble(Console.ReadLine()); double area=GetCircleArea(r); Console.WriteLine("Area of Circle : "+area); Console.ReadKey(); } } |
Output: