Program to Determine Quadrants of a Given Coordinate in C++, Java, and Python

Quadrants of a Coordinate

A coordinate plane is divided into four quadrants:

  • Quadrant 1: (+x, +y)
  • Quadrant 2: (-x, +y)
  • Quadrant 3: (-x, -y)
  • Quadrant 4: (+x, -y)

We will explore three methods to determine the quadrant of a given coordinate using C++, Java, and Python programming.

C++ Implementation

Method 1: Using If-Else Statements

#include 
using namespace std;

void findQuadrant(int x, int y) {
    if (x > 0 && y > 0)
        cout << "Quadrant 1" << endl;
    else if (x < 0 && y > 0)
        cout << "Quadrant 2" << endl;
    else if (x < 0 && y < 0)
        cout << "Quadrant 3" << endl;
    else if (x > 0 && y < 0)
        cout << "Quadrant 4" << endl;
    else
        cout << "Point lies on the axis" << endl;
}

int main() {
    int x, y;
    cout << "Enter x and y coordinates: ";
    cin >> x >> y;
    findQuadrant(x, y);
    return 0;
}

Java Implementation

Method 1: Using If-Else Statements

import java.util.Scanner;

public class QuadrantFinder {
    public static void findQuadrant(int x, int y) {
        if (x > 0 && y > 0)
            System.out.println("Quadrant 1");
        else if (x < 0 && y > 0)
            System.out.println("Quadrant 2");
        else if (x < 0 && y < 0)
            System.out.println("Quadrant 3");
        else if (x > 0 && y < 0)
            System.out.println("Quadrant 4");
        else
            System.out.println("Point lies on the axis");
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter coordinates (x, y): ");
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        findQuadrant(x, y);
        scanner.close();
    }
}

Python Implementation

Method 1: Using If-Else Statements

def find_quadrant(x, y):
    if x > 0 and y > 0:
        print("Quadrant 1")
    elif x < 0 and y > 0:
        print("Quadrant 2")
    elif x < 0 and y < 0:
        print("Quadrant 3")
    elif x > 0 and y < 0:
        print("Quadrant 4")
    else:
        print("Point lies on the axis")

x = int(input("Enter x-coordinate: "))
y = int(input("Enter y-coordinate: "))
find_quadrant(x, y)
Numbers

Below You will find some of the most important codes in languages like C, C++, Java, and Python. These codes are of prime importance for college semester exams and online tests.

Getting Started

HCF - Highest Common Factor: C C++ Java Python

LCM - Lowest Common Multiple: C C++ Java Python

GCD - Greatest Common Divisor: C C++ Java Python

Binary to Decimal Conversion: C C++ Java Python

Octal to Decimal Conversion: C C++ Java Python

Hexadecimal to Decimal Conversion: C C++ Java Python

Decimal to Binary Conversion: C C++ Java Python

Decimal to Octal Conversion: C C++ Java Python

Decimal to Hexadecimal Conversion: C C++ Java Python

Binary to Octal Conversion: C C++ Java Python

Quadrants in which a given coordinate lies: C C++ Java Python

Addition of Two Fractions: C C++ Java Python

Calculate the Area of a Circle: C C++ Java Python

Convert Digit/Number to Words: C C++ Java Python

Finding Roots of a Quadratic Equation: C C++ Java Python