- 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

# C program to find in which quadrant the coordinates lie.

## Problem

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.

## Solution

- 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

## Example

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; }

## Output

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++
- C++ Program to find out the cost to travel all the given coordinates
- Program to find minimum cost to connect each Cartesian coordinates in C++
- C++ program to find out the center coordinates and the height of a building
- 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 minimum radius such that atleast k point lie inside the circle in C++
- Find coordinates of the triangle given midpoint of each side in C++
- C++ Program to find which episode we have missed to watch
- C++ program to find whether only two parallel lines contain all coordinates points or not
- Finding Quadrant of a Coordinate with respect to a Circle in C++
- JavaScript code to find the coordinates of every link in a page
- Find the Number which contain the digit d in C++
- How to find the coordinates of the cursor relative to the screen with JavaScript?

Advertisements