-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharea.c
113 lines (67 loc) · 1.87 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Andrea Corro
// Fun Fact: I've been swimming competitively for almost 5 years.
#include <stdio.h>
#include <math.h>
void triangle() {
int base, height;
float area;
printf("\nEnter the base: ");
scanf("%d", &base);
printf("Enter the height: ");
scanf("%d", &height);
area = (base*height)/2;
printf("\nThe area is %.2f\n\n", area);
}
void rectangle() {
int length, width;
float area;
printf("\nEnter the length: ");
scanf("%d", &length);
printf("Enter the width: ");
scanf("%d", &width);
area = length*width;
printf("\nThe area is %.2f\n\n", area);
}
void square() {
int side;
float area;
printf("\nEnter the length of a side: ");
scanf("%d", &side);
area = side*side;
printf("\nThe area is %.2f\n\n", area);
}
void circle() {
int radius;
float area;
printf("\nEnter the radius: ");
scanf("%d", &radius);
area = M_PI*(radius*radius);
printf("\nThe area is %.2f\n\n", area);
}
int main() {
int shape = 0;
while (shape != 5) {
printf("==============================\n\n");
printf("1) Triangle\n");
printf("2) Rectangle\n");
printf("3) Square\n");
printf("4) Circle\n");
printf("5) Quit\n\n");
printf("Which shape? ");
scanf("%d", &shape);
if (shape == 1) {
triangle();
}
else if (shape == 2) {
rectangle();
}
else if (shape == 3) {
square();
}
else if (shape == 4) {
circle();
}
}
printf("\nGoodbye!\n");
return 0;
}