[Practice] Calculate Area - Structs, Unions, and Enums


Submit solution

Points: 15
Time limit: 0.5s
Memory limit: 3M

Author:
Problem type
Allowed languages
C

Problem Definition

Write a C program that defines a struct called "Shape" with a union member "dimensions." The union should have two members: length and radius, both of type float. The struct should also have an enum member called "type" with constants: Circle and Rectangle. The program should ask the user to enter the type of shape and, based on the type, prompt the user to enter the corresponding dimensions. Then, calculate and display the area of the shape.

Test Data

Sample Input 1

9

Sample Output 1

Invalid choice!

Sample Input 2

1 24

Sample Output 2

Area of the circle: 1808.6400 units

Sample Input 3

2 24.72 44.86

Sample Output 3

Area of the rectangle: 1108.9392 units


Comments

There are no comments at the moment.