Program to find the quadrant in which the given coordinates lie

Select Articles

Program to find the quadrant in which the given coordinates lie

Program to find the quadrant in which the given coordinates lie is discussed here. Input a point from the user and find the quadrant in which the given coordinates lie.

 

DESCRIPTION

If it is in 1st Quadrant, then display Ist Quadrant,

if it is in 2nd Quadrant, then display IInd Quadrant,

if it is in 3rd Quadrant, then display IIIrd Quadrant,

if it is in 4th Quadrant, then display IVth Quadrant and

if it is in center display Origin

 

INPUT FORMAT:

Input consist of 2 integers.

First input corresponds to x co-ordinate.

Second input corresponds to y co-ordinate.
 

SAMPLE INPUT AND OUTPUT:

Input:

5

6

Output:

Ist Quadrant
 

Program to find the quadrant in which the given coordinates lie

C

// C program to find the quadrant in which the given coordinates lie

#include

int main()

{

//Fill the code

    int a,b;

    scanf(“%d %d”,&a,&b);

    if(a > 0 && b > 0)

        printf(“Ist Quadrant”);

    else if(a < 0> 0)

        printf(“IInd Quadrant”);

    else if(a < 0>

        printf(“IIIrd Quadrant”);

    else if(a > 0 && b < 0>

        printf(“IVth Quadrant”);

    else

        printf(“Origin”);

    return 0;

}

 

C++

// C++ program to find the quadrant in which the given coordinates lie

#include

using namespace std;

int main()

{

//Fill the code

    int a,b;

    cin >> a >> b;

    if(a > 0 && b > 0)

        cout << “Ist Quadrant”;

    else if(a < 0> 0)

        cout << “IInd Quadrant”;

    else if(a < 0>

        cout << “IIIrd Quadrant”;

    else if(a > 0 && b < 0>

        cout << “IVth Quadrant”;

    else

        cout << “Origin”;

return 0;

}

 

JAVA 8 

// Java program to find the quadrant in which the given coordinates lie

import java.util.*;

public class Main

{

    public static void main(String[] args) 

    {

        Scanner sc = new Scanner(System.in);

        int a,b;

        a = sc.nextInt();

        b = sc.nextInt();

        if(a > 0 && b > 0)

            System.out.print(“Ist Quadrant”);

        else if(a < 0> 0)

            System.out.print(“IInd Quadrant”);

        else if(a < 0>

            System.out.print(“IIIrd Quadrant”);

        else if(a > 0 && b < 0>

            System.out.print(“IVth Quadrant”);

        else

            System.out.print(“Origin”);

    }

}

 

PYTHON 3 

# Python program to find the quadrant in which the given coordinates lie

a = int(input())

b = int(input())

if(a > 0 and b > 0):

    print(“Ist Quadrant”)

elif(a < 0> 0):

    print(“IInd Quadrant”)

elif(a < 0>

    print(“IIIrd Quadrant”)

elif(a > 0 and b < 0>

    print(“IVth Quadrant”)

else:

    print(“Origin”)
 

OUTPUT

-2

-3

IIIrd Quadrant