The Cartesian plane is divided into four quadrants based on the signs of the x and y coordinates:
(x > 0, y > 0)(x < 0, y > 0)(x < 0, y < 0)(x > 0, y < 0)Special Cases:
(0, 0) → Lies at the center of the coordinate system.(x ≠ 0, y = 0) → Lies on the x-axis.(x = 0, y ≠ 0) → Lies on the y-axis.x and y.if-else statements:
x > 0 and y > 0, it is in Quadrant 1.x < 0 and y > 0, it is in Quadrant 2.x < 0 and y < 0, it is in Quadrant 3.x > 0 and y < 0, it is in Quadrant 4.x == 0 and y == 0, it is the Origin.x == 0 and y ≠ 0, it lies on the Y-Axis.x ≠ 0 and y == 0, it lies on the X-Axis.cCopyEdit#include <stdio.h>
int main() {
int x, y;
// Input the coordinates
printf("Enter the x and y coordinates: ");
scanf("%d %d", &x, &y);
// Determine the quadrant or special case
if (x > 0 && y > 0) {
printf("The point (%d, %d) lies in Quadrant 1.\n", x, y);
} else if (x < 0 && y > 0) {
printf("The point (%d, %d) lies in Quadrant 2.\n", x, y);
} else if (x < 0 && y < 0) {
printf("The point (%d, %d) lies in Quadrant 3.\n", x, y);
} else if (x > 0 && y < 0) {
printf("The point (%d, %d) lies in Quadrant 4.\n", x, y);
} else if (x == 0 && y == 0) {
printf("The point (%d, %d) lies at the Origin.\n", x, y);
} else if (x == 0) {
printf("The point (%d, %d) lies on the Y-Axis.\n", x, y);
} else {
printf("The point (%d, %d) lies on the X-Axis.\n", x, y);
}
return 0;
}
x and y as input.| Input (x, y) | Expected Output |
|---|---|
5 7 | The point (5, 7) lies in Quadrant 1. |
-3 8 | The point (-3, 8) lies in Quadrant 2. |
-4 -6 | The point (-4, -6) lies in Quadrant 3. |
9 -2 | The point (9, -2) lies in Quadrant 4. |
0 0 | The point (0, 0) lies at the Origin. |
0 5 | The point (0, 5) lies on the Y-Axis. |
-7 0 | The point (-7, 0) lies on the X-Axis. |
| Approach | Time Complexity | Space Complexity |
|---|---|---|
| If-else approach | O(1) | O(1) |
x and y.This type of program is frequently asked in placement exams as