【发布时间】:2015-12-01 23:35:52
【问题描述】:
所以我是 C 编程的新手,我一直在尝试制作一个程序,它会根据现有算法告诉我某个点是否在多边形内。我希望程序询问我输入数据并给我结果(0 或 1)我做了一些东西,但我有点卡在最后,不知道如何完成这项工作。
我没有任何错误,我没有得到任何输出。它要求我输入所需的值,最后它没有返回它应该返回的值(输入或输出;0 或 1
int main() {
int n, s, d, vertx[6], verty[6], testx, testy, i, j, c = 0;
printf("Enter the number of vertices of the polygon\n");
scanf("%d", &n);
printf("Enter the x coordinates of the polygon\n");
for (s = 0; s < n; s++)
scanf("%d", &vertx[6]);
printf("Enter the y coordinates of the polygon\n");
for(d = 0; d < n; d++)
scanf("%d", &verty[6]);
printf("Enter the x and y test coordinates\n");
scanf("%d%d", &testx, &testy);
for (i = 0, j = n-1; i < n; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]- verty[i]) + vertx[i]) )
c = !c;
}
return c;
printf("%d", &c);
}
我希望有人愿意在这方面帮助我一点。 谢谢!
【问题讨论】:
-
您需要指定问题。是否有错误,是否得到不正确的输出等。
-
我没有任何错误,我没有得到任何输出。它要求我输入所需的值,最后它没有返回它应该返回的值(输入或输出;0 或 1)