我想问一下这个功能是否正确。它应该检查点是否在矩形内,如果是则打印出来。
#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;
}
添加了整个代码,也许对你们来说会更清楚。