Notice
Recent Posts
Recent Comments
Link
빙수달 게임 개발 노트
[C++] 점이 원 안에 있는지 판별하는 프로그램 본문
#include <iostream>
using namespace std;
struct Circle {
double x1;
double y1;
double radius;
};
struct Dot {
double a1;
double b1;
};
double circle_dot_distance(Circle* C, Dot* D);
int main(void)
{
Circle circle1;
Dot dot1;
cin >> circle1.x1 >> circle1.y1 >> dot1.a1 >> dot1.b1;
cout << "원의 중심은 (" << circle1.x1 << "," << circle1.y1 << ")이고 점은 (" << dot1.a1 << "," << dot1.b1 << ")이다.\n";
circle1.radius = 0;
cin >> circle1.radius;
cout << "원의 반지름은 " << circle1.radius << "이다.\n";
if (circle1.radius > circle_dot_distance(&circle1,&dot1))
{
cout << "점은 원 내부에 있습니다.\n";
}
else if (circle1.radius < circle_dot_distance(&circle1, &dot1))
{
cout << "점은 원 밖에 있습니다.\n";
}
else
{
cout << "원 둘레 위에 점이 있습니다.\n";
}
return 0;
}
double circle_dot_distance(Circle *C, Dot *D)
{
double circle_dot_distance;
circle_dot_distance = sqrt(((D->a1 - C->x1) * (D->a1 - C->x1) + (D->b1 - C->y1) * (D->b1 - C->y1)));
return circle_dot_distance;
}

'Programming > C++' 카테고리의 다른 글
| [C++] 학교 사물함 열기 (0) | 2024.12.19 |
|---|---|
| [C++] 두 선의 교차점을 구하는 프로그램 (0) | 2024.12.19 |
| [C++] 동전 시뮬레이션 프로그램 (0) | 2024.12.18 |
| [C++] 두 원의 관계를 판단하는 프로그램 (0) | 2024.12.18 |
| [C++] 함수 포인터를 이용한 계산기 (0) | 2024.12.18 |