Write a program to find the Quadrants in which coordinates lie

04 May 2022

Write a program to find the Quadrants in which coordinates lie


Desciption

 

Get the value of x and y coordinates as input from the user and check in which quadrant the point lies and print it.

 

Input

10  20

Output

This point lies in first quadrant.

 

Input

-10  20

Output

This point lies in second quadrant.


C Program

#include <stdio.h>

int main()

{

    int x, y;

      printf("Enter the value for x and y: ");

      scanf("%d %d", &x, &y);

      if (x > 0 && y > 0)

      printf("This point lies in the first quadrant.");

      else if (x < 0 && y > 0)

      printf("This point lies in the second quadrant.");

      else if (x < 0 && y < 0)

      printf("This point lies in the third quadrant.");

      else if (x > 0 && y < 0)

     printf("This point lies in the fourth quadrant.");

     else if (x == 0 && y == 0)

     printf("This point lies at the orgin.");

    return 0;

}


 

C++ Program

#include <iostream>

using namespace std;

int main()

{

    int x, y;

      cout<<"Enter the value for x and y: ";

      cin>>x>>y;

      if (x > 0 && y > 0)

      cout<<"This point lies in the first quadrant.";

      else if (x < 0 && y > 0)

      cout<<"This point lies in the second quadrant.";

      else if (x < 0 && y < 0)

      cout<<"This point lies in the third quadrant.";

      else if (x > 0 && y < 0)

     cout<<"This point lies in the fourth quadrant.";

     else if (x == 0 && y == 0)

     cout<<"This point lies at the orgin.";

    return 0;

}


Java

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value for x and y: ");

int x = sc.nextInt();

int y = sc.nextInt();

if (x > 0 && y > 0)

        System.out.println("This point lies in the first quadrant.");

      else if (x < 0 && y > 0)

      System.out.println("This point lies in the second quadrant.");

      else if (x < 0 && y < 0)

      System.out.println("This point lies in the third quadrant.");

      else if (x > 0 && y < 0)

     System.out.println("This point lies in the fourth quadrant.");

     else if (x == 0 && y == 0)

     System.out.println("This point lies in the orgin.");

}

}

 

 

 


 

Python

x  = int(input('Enter value for x :'))

y = int(input('Enter value for y :'))

if x > 0 and y > 0:

    print('This point lies in the first quadrant')

elif x < 0 and y > 0:

    print('This point lies in the second quadrant')

elif x < 0 and y < 0:

    print('This point lies in the third quadrant')

elif x > 0 and y < 0:

    print('This point lies in the fourth quadrant')

else: 

    print('This point lies at the origin')

 

Related Articles

Ask Us Anything !