-
Notifications
You must be signed in to change notification settings - Fork 0
/
mid.c
47 lines (41 loc) · 1.06 KB
/
mid.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
#include <stdio.h>
#include <stdbool.h>
struct Circle{
int x_centre;
int y_centre;
int r;
};
struct Point{
int x;
int y;
};
bool point_in_circle(struct Point *p, struct Circle *c){
return (((c->x_centre - p->x)*(c->x_centre - p->x)+
(c->y_centre - p->y)*(c->y_centre - p->y)) < (c->r * c->r));
}
bool compare_circles(struct Circle c1, struct Circle c2){
return ((c1.x_centre == c2.x_centre) &&
(c1.y_centre == c2.y_centre) &&
(c1.r == c2.r));
}
bool compare_points(struct Point *p1, struct Point *p2){
return (p1->x == p2->x) && (p1->y == p2->y);
}
void update_r(struct Circle * c, int new_r){
c->r = new_r;
}
int main(void){
struct Circle c1={0,0,10};
struct Circle c2={0,10,10};
struct Circle c3={0,10,20};
struct Point p1={2,2};
struct Point p2={12,23};
printf("%d\n", point_in_circle(&p1, &c1));
printf("%d\n", compare_circles(c1, c2));
printf("%d\n", compare_points(&p1, &p2));
p2.x = 2;
p2.y = 2;
printf("%d",compare_points(&p1, &p2));
update_r(&c2, 20);
printf("%d\n", compare_circles(c2, c3));
}