
Problem
Solution
Submissions
Calculate the Area of a Circle
Certification: Basic Level
Accuracy: 66.67%
Submissions: 6
Points: 5
Write a C# program to calculate the area of a circle given its radius. The formula for calculating the area of a circle is A = π × r², where π (pi) is approximately equal to 3.14159 and r is the radius of the circle.
Implement the CalculateArea(double radius) function, which:
- Takes a double value representing the radius of the circle
- Returns a double value representing the area of the circle
- Handles edge cases appropriately (negative radius should return 0)
Example 1
- Input: radius = 5.0
- Output: 78.54
- Explanation:
- Area = π × 5² = 3.14159 × 25 = 78.54 (rounded to 2 decimal places)
Example 2
- Input: radius = 10.0
- Output: 314.16
- Explanation:
- Area = π × 10² = 3.14159 × 100 = 314.16 (rounded to 2 decimal places)
Constraints
- -1000.0 <= radius <= 1000.0
- Return 0 if radius is negative
- Time Complexity: O(1)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use Math.PI for the value of π (3.14159...)
- Square the radius using Math.Pow(radius, 2) or simply radius * radius
- Check if radius is negative and return 0 if it is
- Use proper double precision to maintain accuracy