- Related Questions & Answers
- Coordinates of rectangle with given points lie inside 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++
- C++ program to find whether only two parallel lines contain all coordinates points or not
- Find minimum radius such that atleast k point lie inside the circle in C++
- JavaScript code to find the coordinates of every link in a page
- How to find the coordinates of the cursor relative to the screen with JavaScript?
- Finding Quadrant of a Coordinate with respect to a Circle in C++
- Find the Number which contain the digit d in C++
- Find minimum area of rectangle with given set of coordinates in C++
- Program to find which element occurs exactly once in Python
- Which is the fastest algorithm to find prime numbers using C++?
- Program to find the Discount Percentage in C++

- 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

Advertisements