C Program: Determine the Quadrant of point(x,y) by using AND Operator and else-if Statement

Engg.... | 02:24 | | | Best Blogger Tips
Quadrants

Function of scanf():
  • scanf() is the Input Statement.  
  • scanf() statement is used to give Input at the run time. 
  • Format: scanf(" %f " , &a);
  • In the above format 'a' is variable and value of 'a' is assigned at the run time. 
  • In scanf() statement, character 'f ' indicates the format i.e ("  ");
Statement of C program: Enter the value of x and y and determine the quadrant of point(x,y) :


#include<stdio.h>
#include<conio.h>

void main()
{
float x,y ;
clrscr();
printf("Enter the value of x and y\n ");              //  \n  used for next line character.
scanf(" x=%f  y=%f" , &x , &y);                           

if (x>0 && y>0)                     // Both conditions must be True in order to execute the statement.
{
printf(" point(%f,%f) lies in Ist quad\n ,x,y");
}
else if (x<0 && y>0)
{
printf(" point(%f,%f) lies in IInd quad\n , x,y");
}
else if (x<0 && y<0)
{
printf(" point(%f,%f) lies in IIIrd quad\n ,x,y");
}
else if (x>0 && y<0)
{
printf(" point(%f,%f) lies in IVth quad\n , x,y");
}
else( x==0 && y==0)
{
printf("point(%f,%f) lies at the origin\n" ,x,y);
}
getch();
}

Output1:
Enter the value of x and y
x=2   y=5                          // As both conditions i.e ( x>0 and y>0) are True so statement is executed
point(2,5) lies in Ist quad 



Output2:
Enter the value of x and y
x=2   y=-6                         // As both conditions i.e ( x>0 and y<0) are True so statement is executed
point(2,-6) lies in IVth quad 
 


Output3:
Enter the value of x and y
x=0   y=0                          // As both conditions i.e ( x=0 and y=0) are True so statement is executed
point(0,0) lies at the origin 
 


Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

0 comments:

Post a Comment