C Program to Find Quadrant of a Point in Cartesian Plan.

In this article, we are going to learn the C program to find the quadrant of a given coordinate point. Before moving to the code section let's understand about Cartesian plan.


What is Cartesian Plan?

The Cartesian plane, also known as the Cartesian coordinate system or Cartesian grid, is a two-dimensional coordinate system used to locate points in a plane using two perpendicular number lines, known as the x-axis and y-axis


In the Cartesian plane, any point can be represented by an ordered pair (x, y), where "x" represents the horizontal distance from the y-axis (positive to the right and negative to the left), and "y" represents the vertical distance from the x-axis (positive upward and negative downward).


The x-axis and y-axis intersect at a point called the origin, represented as (0, 0). The x-axis extends infinitely to the right and left, while the y-axis extends infinitely upwards and downwards.


Quadrant of point in Cartesian Plan

Quadrant in Cartesian Plan.

In a Cartesian plane, there are four quadrants. The x-axis and y-axis divide the plane into four regions, each known as a quadrant.


First Quadrant (Q1): The first quadrant is located in the upper right-hand side of the plane. In this quadrant, both the x and y coordinates are positive. 

Example: (2, 3)


Second Quadrant (Q2): The second quadrant is on the upper left-hand side of the plane. In this quadrant, the x coordinate is negative, and the y coordinate is positive.

Example: (2, -3)


Third Quadrant (Q3): The third quadrant is on the lower left-hand side of the plane. In this quadrant, both the x and y coordinates are negative.

Example: (-2, -3)


Fourth Quadrant (Q4): The fourth quadrant is on the lower right-hand side of the plane. In this quadrant, the x coordinate is positive, and the y coordinate is negative.

Example: (2, -3)


C code to find the quadrant of a given point.

//C program to find quadrant of a point
#include <stdio.h>

int main() {
    int x, y;

    // Input the coordinates of the point
    printf("Enter the x-coordinate: ");
    scanf("%d", &x);
    printf("Enter the y-coordinate: ");
    scanf("%d", &y);

    // Determine the quadrant of the point
    if (x > 0 && y > 0) {
        printf("(%d, %d) lies in the First Quadrant (Q1).\n", x, y);
    } else if (x < 0 && y > 0) {
        printf("(%d, %d) lies in the Second Quadrant (Q2).\n", x, y);
    } else if (x < 0 && y < 0) {
        printf("(%d, %d) lies in the Third Quadrant (Q3).\n", x, y);
    } else if (x > 0 && y < 0) {
        printf("(%d, %d) lies in the Fourth Quadrant (Q4).\n", x, y);
    } else if (x == 0 && y == 0) {
        printf("(%d, %d) is at the origin.\n", x, y);
    } else if (x == 0) {
        printf("(%d, %d) lies on the y-axis.\n", x, y);
    } else {
        printf("(%d, %d) lies on the x-axis.\n", x, y);
    }

    return 0;
}
Output:
Enter the x-coordinate: 2
Enter the y-coordinate: -3
(2, -3) lies in the Fourth Quadrant (Q4).

Time Complexity: O(1) 
Space Complexity: O(1)

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS