Saturday, November 3, 2018

26. WAP to determine the quadrant in which a point lies.

#include<stdio.h>
#include<conio.h>
void main()
{
   int x,y;
   printf("Enter the X co-ordinate of the point: ");
   scanf("%d",&x);
   printf("Enter the Y co-ordinate of the point: ");
   scanf("%d",&y);
   if(x!=0 && y==0)
    printf("\nPoint lies on the x-axis");
   else if(x==0 && y!=0)
    printf("\nPoint lies on the y-axis");
   else if(x>0)
   {
    if(y>0)
          printf("\nPoint lies in the first quadrant.");
else
           printf("\nPoint lies in the fourth quadrant.");
   }
   else if(x<0)
   {
    if(y>0)
          printf("\nPoint lies in the second quadrant.");
else
           printf("\nPoint lies in the third quadrant.");
   }
   else
    printf("\nPoint lies at the origin.");
   
   /*
   if(x!=0 && y==0)
    printf("\nPoint lies on the x-axis");
   else if(x==0 && y!=0)
    printf("\nPoint lies on the y-axis");
   else if(x>0 && y>0)
    printf("\nPoint lies in the first quadrant.");
   else if(x<0 && y>0)
    printf("\nPoint lies in the second quadrant.");
   else if(x<0 && y<0)
    printf("\nPoint lies in the third quadrant.");
   else if(x>0 && y<0)
    printf("\nPoint lies in the fourth quadrant.");
   else
    printf("\nPoint lies at the origin.");
   */

   getch();
}


Output:





Please have a look at the below lesson posted on my YouTube channel:

No comments:

Post a Comment