c - C中的结构,检查点是否在圆圈内

标签 c structure

您好,我尝试编写代码,但它显示有错误,但我没有看到任何错误,代码必须从 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/

相关文章:

c++ - 对数组进行排序并维护元素的旧索引

c - 使用qsort的数组的排序结构

c - 程序不工作

c - 删除链表中的所有节点

c - 删除C编程中的所有结构条目

c - 指向结构体中指针的指针

c - 错误的 Visual C float / double 转换?

c - 当我以 uLong 形式访问数组时会发生什么,该数组最初被声明为 unsigned short?

c - 当我在无限循环中使用 gettimeofday() 时程序意外停止

c - 将结构传递给函数