我想问这个函数是否正确。它应该检查点是否在矩形内,如果是,则打印出来。矩形内的点
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x;
int y;
}point;
typedef struct {
point A;
point B;
}rectangle;
int main() {
rectangle s;
point T;
printf("Enter rectangle A point x coordinate :\n");
scanf("%d", &s.A.x);
printf("Enter rectangle A point y coordinate :\n");
scanf("%d", &s.A.y);
printf("Enter rectangle B point x coordinate :\n");
scanf("%d", &s.B.x);
printf("Enter rectangle B point y coordinate :\n");
scanf("%d", &s.B.y);
printf("\nrectangle - A(%d, %d), B(%d, %d) \n", s.A.x, s.A.y, s.B.x, s.B.y);
for(int i =0; i<2; i++){
printf ("X: ");
scanf ("%d", &T.x);
printf ("Y: ");
scanf ("%d", &T.y);
}
int is_inside(point A, point B){
if((s.A.x <= T.x) && (T.x <= s.B.x) && (s.A.y <= T.y) && (T.y <= s.B.y)) printf("Point (%d, %d)is inside rectangle \n",T.x, T.y);
else printf("No");
}
return 0;
}
添加整个代码也许它会更清楚地给你们。
我纠正它,但为什么printf的什么都不做? – AndriusK
@Atskalunas我的猜测是你没有通过正确的价值观。在调试器中设置'if'行,并检查条件中使用的变量。 – dasblinkenlight
以某封信为例:A,B表示在当前上下文中找不到。 – AndriusK