嗨,我尝试编写代码,但显示出错误,但没有看到任何错误,该代码必须从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;
}
最佳答案
在其中放置了&f而不是%f的scanf
scanf("&f",&dot1.x);
关于c - C中的结构,检查圆点是否在圆中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29645988/