C Exercises: Find the quadrant to which a coordinate belongs

C Basic Declarations and Expressions: Exercise-37 with Solution

Write a C program to read the coordinates (x, y) (in the Cartesian system) and find the quadrant to which it belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).

Note: A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of numerical coordinates.
These are often numbered from 1st to 4th and denoted by Roman numerals: I (where the signs of the (x,y) coordinates are I(+,+), II (−,+), III (−,−), and IV (+,−).

Sample Solution:

C Code:

#include <stdio.h>
int main() {
    int x, y;

    // Prompt for user input
    printf("Input the Coordinate(x,y): ");
    printf("\nx: "); 
    scanf("%d", &x);
    printf("y: ");
    scanf("%d", &y);

    // Check which quadrant the point lies in
    if(x > 0 && y > 0) {
    else if(x > 0 && y < 0) {			
    else if(x < 0 && y < 0) {
    else if(x < 0 && y > 0) {

    return 0;

Sample Output:

Input the Coordinate(x,y):                                             
x: 25                                                                  
y: 15                                                                  


C Programming Flowchart: Find the quadrant to which a coordinate belongs

C programming Code Editor:

Previous: Write a C program to read a password until it is correct. For wrong password print "Incorrect password" and for correct password print "Correct password" and quit the program. The correct password is 1234.
Next: Write a program that reads two numbers and divide the first number by second number. If the division not possible print "Division not possible".

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.