Quadrants In Which Coordinates Lie | C Program

Quadrants in which coordinates lie in C :-

Here, we will discuss the program for Quadrants In Which Coordinates Lie in C.The C program reads the coordinate point in a x-y coordinate system and identify the quadrant. The program takes X and Y. On the basis of x and y value, the program will identify on which quadrant the point lies. The program will read the value of x and y variable. If-else condition is used to identify the quadrant of the given value.

Ex:- X and Y coordinates are 20, 30  these lie in 4th quadrant because in mathematics quadrants rules are following

  • x  is positive  integer and y is also positive  integer so-that  quadrant is a first quadrant.
  • x is negative integer and y is  positive integer so-that  Quadrant  is a second quadrant.
  • x is negative integer and y is   also negative integer so -that Quadrant is a third quadrant.
  • x is positive integer and y is  negative integer so-that is a first quadrant.
Quadrant in which coordinates lie in C

Working:-

Step 1: Start

Step 2: The user asked to put value for x and y variables

Step 3: If-else condition is used to determine the value of the given value

Step 4: Check the condition, if x variable’s value is greater than 0 and the variable y is greater than 0.

Step 5: If the condition is true then print the output as first quadrant.

Step 6: If the condition is false then check the condition if x is lesser than 0 and the y variable is greater than 0.

Step 7: If the condition is true then print the output as second quadrant.

Step 8: If the condition is false, execute another statement to check if the value of x is less than 0 and y is less than 0.

Step 9: If the condition is true then print the output as the third quadrant.

Step 10: If the condition is false, then check if x variable is greater than 0 and the y value is less than 0.

Step 11: If the condition is true then print the output as the fourth quadrant.

Step 12: If the condition is false, then execute another statement where x value is equal to 0 and y variable is equal to 0.

Step 13: Print the output as an origin.

Step 14: Stop

Quadrants in which coordinates lies
Competitive Coding Techniques

C Program:-

#include<stdio.h> 
int main()
{
 //for initialization of coordinates
      int x, y; //user input
      printf("Insert the value for variable X and Y\n");
      scanf("%d %d", &x, &y);
 //find true condition of first quadrant 
      if (x > 0 && y > 0)
      printf("point (%d, %d) lies in the First quadrant\n",x,y);
 //find second quadrant
      else if (x < 0 && y > 0)
      printf("point (%d, %d) lies in the Second quadrant\n",x,y);
//To find third quadrant
      else if (x < 0 && y < 0)
      printf("point (%d, %d) lies in the Third quadrant\n",x,y);
//To find Fourth quadrant
           else if (x > 0 && y < 0)
     printf("point (%d, %d) lies in the Fourth quandrant\n",x,y);
//To find dose not lie on origin
     else if (x == 0 && y == 0)
     printf("point (%d, %d) lies at the origin\n",x,y);
return 0;
}

Output:-

Insert the value for variable X and Y
10  20
point (10, 20) lies in the First quadrant

Insert the value for variable X and Y
-10 30
point (-10, 30) lies in the Second quadrant

Insert the value for variable X and Y
20  -50
point (-20, -50) lies in the Third quadrant

Insert the value for variable X and Y
35 -15
point (35, -15) lies in the Fourth quadrant