【发布时间】:2021-11-30 11:47:50
【问题描述】:
#include <stdio.h>
char dentroRetangulo(int v1x, int v1y, int v2x, int v2y, int x, int y);
int main()
{
int a, b, c, f,d,g,x,y;
char D, h;
printf("== Coordinates of a rectangle ==\n");
printf("Inform the coordinates of the left inferior corner : \n");
scanf("%d %d", &a, &b);
printf("Inform the coordinates of the superior right corner: \n");
scanf("%d %d", &c, &d);
printf("=== points ===\n");
printf("inform the coordinates of the point (x,y)\n");
scanf("%d %d", &f, &g);
h = dentroRetangulo(a,b,c,d,f,g);
if(h == D)
{
printf("O ponto(%d, %d) encontra-se dentro do retangulo", x, y);
}
return 0;
}
char dentroRetangulo(int v1x, int v1y, int v2x, int v2y, int x, int y)
{
char D;
char B;
char F;
if(x>v1x && x<v2x || y> v1y && y<v2y)
{
return D;
}
所以基本上,这个函数是关于检查一个点是否在一个矩形内,下角x,y坐标是v1x和v1y,上坐标是v2x和v2y,并且在主函数中假设用户输入 x 和 y 坐标以验证它们是否在其中,我在 C 语言中有点像新手,但我已经花了一整天的时间试图找出我在这里做错了什么,我可能太愚蠢了看看这里出了什么问题
【问题讨论】:
-
所以函数检查语句是否为真并返回一个 D 值,给主函数,如果 h == D 从函数返回的字符,if 语句检查它并打印点在矩形内,对不起,我是巴西人,我忘了翻译最后一个 printf
-
是什么让你觉得你做错了什么?有什么症状?你观察什么?你想要什么行为?
-
另外,
if(x>v1x && x<v2x || y> v1y && y<v2y)应该有&&,而你有||,因为你希望 all 条件为真。 -
好像你没有发布所有代码
-
@FaustinoDaSilva 不要使用“固定”代码更新问题...如果您愿意,您可以发布固定代码作为答案,但不要更改问题