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


Given a point (x, y), write a C program to find out if it lies on the x-axis, y-axis or on the origin(0, 0).

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)

Logic To Check If Point(x, y) Lies on x-axis or y-axis or Origin
In point (x, y), if x = 0 and y = 0, then the point lies on the origin. If value of x is zero and y is greater than zero, then the point lies on y-axis. If y is zero and x is greater than zero, then the point lies on x-axis.

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

Output:
Point lies on y-axis

Video Tutorial: C Program To Check If Point Lies on x-axis or y-axis or Origin



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

Source Code: C Program To Check If Point Lies on x-axis or y-axis or Origin

  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(x == 0)  
  15.     {  
  16.         printf("Point lies on y-axis\n");  
  17.     }  
  18.     else if(y == 0)  
  19.     {  
  20.         printf("Point lies on x-axis\n");  
  21.     }  
  22.     else  
  23.     {  
  24.         printf("Point neither lies on x-axis nor on y-axis\n");  
  25.     }  
  26.   
  27.     return 0;  
  28. }  

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 x-axis

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

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

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 *