Area of Shapes - Problem
You are given three different shapes and need to calculate their areas based on the provided dimensions:
- Circle: Given radius
r, calculate area using formula π × r² - Rectangle: Given length
land widthw, calculate area using formula l × w - Triangle: Given base
band heighth, calculate area using formula ½ × b × h
The program should read the shape type and its dimensions, then output the calculated area rounded to 2 decimal places.
Note: Use π = 3.14159 for circle calculations.
Input & Output
Example 1 — Circle Area
$
Input:
shape = "circle", dimensions = [5]
›
Output:
78.54
💡 Note:
Circle area = π × r² = 3.14159 × 5² = 3.14159 × 25 = 78.54 square units
Example 2 — Rectangle Area
$
Input:
shape = "rectangle", dimensions = [6, 4]
›
Output:
24.00
💡 Note:
Rectangle area = length × width = 6 × 4 = 24.00 square units
Example 3 — Triangle Area
$
Input:
shape = "triangle", dimensions = [8, 3]
›
Output:
12.00
💡 Note:
Triangle area = ½ × base × height = 0.5 × 8 × 3 = 12.00 square units
Constraints
- Shape will be one of: "circle", "rectangle", "triangle"
- Dimensions array will have appropriate length for each shape
- All dimension values will be positive numbers
- Results should be rounded to 2 decimal places
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code