- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Write a program to find the quadrant in which the given coordinates lie.

User has to enter a coordinate at runtime and we need to find the quadrant in which these coordinates lie.

- If both numbers are positive then, it displays the first quadrant.

Example: Input =2, 3 Output = 1st quadrant

- If the first number is negative and the second number is positive then, it displays the second quadrant.

Example: Input = -4, 3 Output= 2nd quadrant

- If the first number is negative and the second number is also negative then, it displays the third quadrant.

Example: Input = -5,-7 Output= 3rd quadrant

- If the first number is positive and the second number is negative then, it displays the fourth quadrant.

Example: Input = 3,-5 Output = 4th quadrant

Following is the C program to find the quadrant in which the given coordinates lie −

#include <stdio.h> int main(){ int a,b; printf("enter two coordinates:"); scanf("%d %d",&a,&b); if(a > 0 && b > 0) printf("1st Quadrant"); else if(a < 0 && b > 0) printf("2nd Quadrant"); else if(a < 0 && b < 0) printf("3rd Quadrant"); else if(a > 0 && b < 0) printf("4th Quadrant"); else printf("Origin"); return 0; }

When the above program is executed, it produces the following output −

Run 1: enter two coordinates:-4 6 2nd Quadrant Run 2: enter two coordinates:-5 -3 3rd Quadrant

- Related Questions & Answers
- Coordinates of rectangle with given points lie inside in C++
- Program to find minimum cost to connect each Cartesian coordinates in C++
- Find all possible coordinates of parallelogram in C++
- How to find the coordinates of the cursor with JavaScript?
- Find the other-end coordinates of diameter in a circler in C++
- Find coordinates of the triangle given midpoint of each side in C++
- Find minimum radius such that atleast k point lie inside the circle in C++
- C++ program to find whether only two parallel lines contain all coordinates points or not
- JavaScript code to find the coordinates of every link in a page
- Finding Quadrant of a Coordinate with respect to a Circle in C++
- How to find the coordinates of the cursor relative to the screen with JavaScript?
- Find the Number which contain the digit d in C++
- Program to find out the number of integral coordinates on a straight line between two points in Python
- Find minimum area of rectangle with given set of coordinates in C++
- Program to find which element occurs exactly once in Python

Advertisements