Write a C++ function that determines in which quadrant a line
drawn from the origin resides. The determination of the quadrant
is made using the angle that the line makes with the positive x
axis as follows:
Note: if the angle is exactly 0,90,180,270 degrees the
corresponding line does not reside in any quadrant but lies on an
axis.
Angle from the
positive x axis Quadrant
Between 0 and 90 degrees =1
Between 90 and 180 degrees =2
Between 180 and 270 degrees =3
Between 270 and 360 degrees = 4
#include <iostream>
using namespace std;
int main(void) {
int angle, quadrant = 0;
cout<<"angle: ";
cin>>angle;
if(angle>=360)
angle = angle%360;
if(angle>0 && angle<90)
quadrant = 1;
else if(angle>90 && angle<180)
quadrant = 2;
else if(angle>180 && angle<270)
quadrant = 3;
else if(angle>270 && angle<360)
quadrant = 3;
else if(angle==0||angle==180)
cout<<"The line does not reside in any quadrant but lies on an axis X"<<endl;
else if(angle==90||angle==270)
cout<<"The line does not reside in any quadrant but lies on an axis Y"<<endl;
if(quadrant!=0)
cout<<"quadrant: "<<quadrant<<endl;
return 0;
}
Comments
Leave a comment