C Program To Check In Which Quadrant The Point Lies


Lets write a C program to determine the position of point(x,y) on the graph of x and y axis.

Important: Always remember that, to specify a point, we always write x-axis value first and then the y-axis value. i.e., (x, y)

Related Read:
C Program To Check If Point Lies on x-axis or y-axis or Origin

Logic To Check The Position of the Point in the graph
We check for 9 conditions to determine the position of the user entered point in the graph.
x and y axis graph
1. Point lies on (0, 0): Origin
2. y = 0 and x > 0. i.e., x is positive: point lies on positive side of x-axis.
3. x = 0 and y > 0. i.e., y is positive: point lies on positive side of y-axis.
4. y = 0 and x < 0. i.e., x is negative: point lies on negative side of x-axis.
5. x = 0 and y < 0. i.e., y is negative: point lies on negative side of y-axis.
6. x > 0 and y > 0. i.e., both x and y are positive: point lies in First Quadrant.
7. x < 0 and y > 0. i.e., x is negative and y is positive: point lies in Second Quadrant.
8. x < 0 and y < 0. i.e., both x and y are negative: point lies in Third Quadrant.
9. x > 0 and y < 0. i.e., x is positive and y is negative: point lies in Forth Quadrant.

Expected Output for the Input

User Input:
Enter the point(x, y)
5
5

Output:
Point lies in First Quadrant

Video Tutorial: C Program To Check In Which Quadrant The Point Lies



YouTube Link: https://www.youtube.com/watch?v=PldmqX9emxE [Watch the Video In Full Screen.]

Source Code: C Program To Check In Which Quadrant The Point Lies

  1. #include < stdio.h >  
  2.   
  3. int main()  
  4. {  
  5.     float x, y;  
  6.   
  7.     printf("Enter the point(x, y)\n");  
  8.     scanf("%f%f", &x, &y);  
  9.   
  10.     if(x == 0 && y == 0)  
  11.     {  
  12.         printf("Point lies on the Origin\n");  
  13.     }  
  14.     else if(y == 0 && x > 0)  
  15.     {  
  16.         printf("Point lies on positive x-axis\n");  
  17.     }  
  18.     else if(x == 0 && y > 0)  
  19.     {  
  20.         printf("Point lies on positive y-axis\n");  
  21.     }  
  22.     else if(y == 0 && x < 0)  
  23.     {  
  24.         printf("Point lies on negative x-axis\n");  
  25.     }  
  26.     else if(x == 0 && y < 0)  
  27.     {  
  28.         printf("Point lies on negative y-axis\n");  
  29.     }  
  30.     else if(x > 0 && y > 0)  
  31.     {  
  32.         printf("Point lies in First Quadrant\n");  
  33.     }  
  34.     else if(x < 0 && y > 0)  
  35.     {  
  36.         printf("Point lies in Second Quadrant\n");  
  37.     }  
  38.     else if(x < 0 && y < 0)  
  39.     {  
  40.         printf("Point lies in Third Quadrant\n");  
  41.     }  
  42.     else if(x > 0 && y <0)  
  43.     {  
  44.         printf("Point lies in Forth Quadrant\n");  
  45.     }  
  46.   
  47.     return 0;  
  48. }  

Output 1:
Enter the point(x, y)
0
0
Point lies on the Origin

Output 2:
Enter the point(x, y)
5
0
Point lies on positive x-axis

Output 3:
Enter the point(x, y)
-5
0
Point lies on negative x-axis

Output 4:
Enter the point(x, y)
0
5
Point lies on positive y-axis

Output 5:
Enter the point(x, y)
0
-5
Point lies on negative y-axis

Output 6:
Enter the point(x, y)
5
5
Point lies in First Quadrant

Output 7:
Enter the point(x, y)
-5
5
Point lies in Second Quadrant

Output 8:
Enter the point(x, y)
-5
-5
Point lies in Third Quadrant

Output 9:
Enter the point(x, y)
5
-5
Point lies in Forth Quadrant

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *