50.2 연습문제: 사각형의 넓이 구하기
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct Rectangle
{
int x1, y1;
int x2, y2;
};
int main(void)
{
struct Rectangle rect;
int area;
rect.x1 = 20;
rect.y1 = 20;
rect.x2 = 40;
rect.y2 = 30;
int width = abs(rect.x2 - rect.x1);
int height = abs(rect.y2 - rect.y1);
area = width * height;
printf("%d\n", area);
return 0;
}
50.3 심사문제: 두 점 사이의 거리 구하기
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
struct Point2D
{
int x;
int y;
};
int main(void)
{
struct Point2D p1;
struct Point2D p2;
double distance;
scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);
int a = abs(p2.x - p1.x);
int b = abs(p2.y - p1.y);
distance = sqrt(pow(a, 2) + pow(b, 2));
printf("%f\n", distance);
return 0;
}