Write a C program to find in which quadrant a coordinate point lies

Description: Take the x and y coordinates of a point. Print the quadrant in which it lies.

Hint:

  • Quadrant 1: x > 0 and y > 0. Quadrant 2: x < 0 and y > 0. Quadrant 3: x < 0 and y < 0. Quadrant 4: x > 0 and y < 0.

C program to find the quadrant of a point

#include <stdio.h>

int main(void) {
    int x, y;

    printf("Enter x and y: ");
    scanf("%d %d", &x, &y);

    if (x > 0 && y > 0) {
        printf("First quadrant\n");
    } else if (x < 0 && y > 0) {
        printf("Second quadrant\n");
    } else if (x < 0 && y < 0) {
        printf("Third quadrant\n");
    } else if (x > 0 && y < 0) {
        printf("Fourth quadrant\n");
    } else {
        printf("The point is on an axis or at the origin\n");
    }
    return 0;
}

Output:

Output of the above program is

Enter x and y: -3 -7
Third quadrant

How it works

  • Both values are negative, so the point is in the third quadrant.
  • If x or y is zero, the point is on an axis, so the last else runs.

Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.