问题:
尝试找出位置 x
和 y
中的点,然后将位置中的点表示为具有两个字段的结构。
因此,根据接受结构的函数,它将返回 1、2、3 或 4。(这些是 4 个象限)
如果 x 和 y 为正,象限 1, 如果 x 为负且 y 为正,则 2 如果 x 为负且 y 为负,象限 3, 如果 x 为正且 y 为负,则为象限 4。
我的大部分问题不是完全理解这个问题,我是否使用结构体获取 x 和 y 的 2 个值并返回数字?
另外,我如何与我的结构交互? 希望我提供了足够的信息,这几乎是我所拥有的全部信息。
代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct coord
{
int x;
int y;
}POINT;
int main(){
int the_point;
scanf("%d", &the_point);
POINT * coord = malloc(50 * sizeof(POINT));
if (the_point)
return 0;
}
最佳答案
首先,你如何读到这一点。看起来您扫描到了the_point
。该变量只是一个 int,这意味着除非您打算解析它或以其他方式操作它,否则您必须确定这是问题中的 x 值还是 y 值。最好明确让用户输入该点的坐标。如:
printf("Enter the x-coord of the input: ");
scanf("%d", &the_point);
///
///assign the_point to the x-coord
///
// do the same thing for y-coord
您将使用箭头运算符来访问结构中的字段,例如:
myStruct->field1 = some_var
您可以使用相同的语法对各个字段运行条件检查。
关于c - 使用结构体确定平面上的点 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53787687/