카테고리 없음2017. 12. 5. 01:04

#include <stdio.h>
#include <math.h> // 제곱근 반환함수인 sqrt 사용

struct Point  // 구조체 point의 정의
{
 int xpos;
 int ypos;
};

int main(void)
{
 struct Point pos1, pos2;
 double distance;

 fputs("Point1 pos : ",stdout);
 scanf("%d %d", &pos1.xpos, &pos1.ypos);
 
 fputs("Point2 pos : ",stdout);
 scanf("%d %d", &pos2.xpos, &pos2.ypos);

 // 두 점간의 거리 계산 공식
 distance = sqrt((double)((pos1.xpos - pos2.xpos) * (pos1.xpos - pos2.xpos) + (pos1.ypos - pos2.ypos) * (pos1.ypos - pos2.ypos)));

 printf("두 점의 거리는 %f 입니다. \n", distance);

}

 

 

 

 

 

Posted by 넓스