帮我用C写一段四象限划分函数
时间: 2023-08-15 19:03:08 浏览: 138
以下为四象限划分函数的C代码实现:
```c
#include <stdio.h>
void quadrant(int x, int y) {
if (x > 0 && y > 0) {
printf("The point (%d, %d) is in the first quadrant.\n", x, y);
}
else if (x < 0 && y > 0) {
printf("The point (%d, %d) is in the second quadrant.\n", x, y);
}
else if (x < 0 && y < 0) {
printf("The point (%d, %d) is in the third quadrant.\n", x, y);
}
else if (x > 0 && y < 0) {
printf("The point (%d, %d) is in the fourth quadrant.\n", x, y);
}
else if (x == 0 && y == 0) {
printf("The point (%d, %d) is at the origin.\n", x, y);
}
else if (x == 0 && y != 0) {
printf("The point (%d, %d) is on the y-axis.\n", x, y);
}
else if (x != 0 && y == 0) {
printf("The point (%d, %d) is on the x-axis.\n", x, y);
}
}
int main() {
int x, y;
printf("Enter the x and y coordinates of a point: ");
scanf("%d %d", &x, &y);
quadrant(x, y);
return 0;
}
```
该函数接收两个参数 x 和 y,代表一个平面直角坐标系上的点的坐标,然后根据点所在的象限或坐标轴输出对应的信息。如果点位于第一象限,则输出 "The point (x, y) is in the first quadrant.";如果点位于第二象限,则输出 "The point (x, y) is in the second quadrant.",以此类推。如果点位于原点,则输出 "The point (x, y) is at the origin.";如果点在 x 轴或 y 轴上,则输出 "The point (x, y) is on the x-axis/y-axis."
阅读全文