我想問這個函數是否正確。它應該檢查點是否在矩形內,如果是,則打印出來。矩形內的點
#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