-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharea.c
36 lines (30 loc) · 680 Bytes
/
area.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
struct Shape {
enum type { Circle = 1, Rectangle } t;
union dimensions {
float length[2];
float radius;
} d;
} s;
int main() {
float area;
// Read the shape type from the user
scanf("%d", (int *)&s.t);
if (s.t == 2) {
// Calculate area for Rectangle
scanf("%f", &s.d.length[0]);
scanf("%f", &s.d.length[1]);
area = s.d.length[0] * s.d.length[1];
printf("Area of the rectangle: %.4f units\n", area);
}
else if (s.t == 1) {
// Calculate area for Circle
scanf("%f", &s.d.radius);
area = 3.14 * s.d.radius * s.d.radius;
printf("Area of the circle: %.4f units\n", area);
}
else {
printf("Invalid choice!\n");
}
return 0;
}