您好,我尝试编写代码,但它显示有错误,但我没有看到任何错误,代码必须从 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);
关于c - C中的结构,检查点是否在圆圈内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29645988/