-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10- (5).c
64 lines (51 loc) · 949 Bytes
/
10- (5).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
#include<stdio.h>
#include<math.h>
typedef struct Rectangle
{
int x;
int y;
}POINT;
POINT translate(POINT p1, POINT p2);
int area(struct Rectangle *r);
int perimeter(struct Rectangle *r);
int is_square(struct Rectangle *r);
int main()
{
struct Rectangle p1, p2, r;
printf("좌표를 입력하시오.");
scanf("%d%d", &p1.x, &p1.y);
scanf("%d%d", &p2.x, &p2.y);
r = translate(p1, p2);
printf("넓이 : %d 둘레 : %d ", area(&r),perimeter(&r));
if (is_square(&r) == 1)
printf("정사각형");
else
printf("정사각형이 아님");
return 0;
}
int area(struct Rectangle *r)
{
int area = 0;
area = r->x*r->y;
return area;
}
int perimeter(struct Rectangle *r)
{
int x1 = 0, y1 = 0;
x1 = r->x * 2;
y1 = r->y * 2;
return x1 + y1;
}
int is_square(struct Rectangle *r)
{
if (r->x == r->y)
return 1;
else return 0;
}
POINT translate(POINT p1, POINT p2)
{
POINT newp;
newp.x = abs(p1.x - p2.x);
newp.y = abs(p1.y - p2.y);
return newp;
}