C中的结构,检查点是否在圆圈中
structure in C,check if the dot is in the circle
你好,我试着写一个代码,但它告诉我有错误,但我没有看到任何错误,代码必须从 X 和 Y 的用户坐标以及圆的 R 半径获取,即第二个坐标X 和 Y 并使用函数检查第二个点是否在圆中。
typedef struct point
{
float x;
float y;
}point;
typedef struct round
{
int R;
point dot2;
}round;
int is_in_cir(point, round);
int main()
{
int ans;
point dot1;
round cir;
printf("Please enter the coordination of the radius: \n");
scanf("%d", &cir.R);
printf("Please enter the coordinates,x and then y:\n");
scanf("%f", &cir.dot2.x);
scanf("%f", &cir.dot2.y);
Printf("Please enter two more coordinates to check if the dot is in the circle\n");
scanf("&f",&dot1.x);
scanf("%f",&dot1.y);
ans = is_in_cir(dot1, cir);
if (ans)
printf("The dot you entered is in the circle");
else printf("The dot you entered isnt in the circle");
_getch();
return 0;
}
int is_in_cir(point a, round b)
{
double ans;
ans = sqrt(pow((b.dot2.x - a.x), 2) + pow((b.dot2.y - a.y), 2));
if (b.R >= ans)
return 1;
return 0;
}
有一个 scanf,你把 &f 而不是 %f
scanf("&f",&dot1.x);
你好,我试着写一个代码,但它告诉我有错误,但我没有看到任何错误,代码必须从 X 和 Y 的用户坐标以及圆的 R 半径获取,即第二个坐标X 和 Y 并使用函数检查第二个点是否在圆中。
typedef struct point
{
float x;
float y;
}point;
typedef struct round
{
int R;
point dot2;
}round;
int is_in_cir(point, round);
int main()
{
int ans;
point dot1;
round cir;
printf("Please enter the coordination of the radius: \n");
scanf("%d", &cir.R);
printf("Please enter the coordinates,x and then y:\n");
scanf("%f", &cir.dot2.x);
scanf("%f", &cir.dot2.y);
Printf("Please enter two more coordinates to check if the dot is in the circle\n");
scanf("&f",&dot1.x);
scanf("%f",&dot1.y);
ans = is_in_cir(dot1, cir);
if (ans)
printf("The dot you entered is in the circle");
else printf("The dot you entered isnt in the circle");
_getch();
return 0;
}
int is_in_cir(point a, round b)
{
double ans;
ans = sqrt(pow((b.dot2.x - a.x), 2) + pow((b.dot2.y - a.y), 2));
if (b.R >= ans)
return 1;
return 0;
}
有一个 scanf,你把 &f 而不是 %f
scanf("&f",&dot1.x);