The source code to read coordinate points and determine their quadrant is given below. The given program is compiled and executed successfully.
# Ruby program to read coordinate points
# and determine its quadrant
X=0.0;
Y=0.0;
print "Enter value of X: ";
X = gets.chomp.to_f;
print "Enter value of Y: ";
Y = gets.chomp.to_f;
if X == 0 && Y == 0
print "Point (",X,",",Y,") lies at the origin";
elsif X > 0 && Y > 0
print "Point (",X,",",Y,") lies in the First quadrant";
elsif X < 0 && Y > 0
print "Point (",X,",",Y,") lies in the Second quadrant";
elsif X < 0 && Y < 0
print "Point (",X,",",Y,") lies in the Third quadrant";
elsif X > 0 && Y < 0
print "Point (",X,",",Y,") lies in the Fourth quadrant";
end
Output:
Enter value of X: 12
Enter value of Y: 15
Point (12,15) lies in the First quadrant
Explanation:
In the above program, we created two variables X and Y, that are initialized with 0.0. Then we read X, Y coordinate from the user and determined its quadrant, and printed the appropriate message.
Program/Source Code:
The source code to read coordinate points and determine their quadrant is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two variables X and Y, that are initialized with 0.0. Then we read X, Y coordinate from the user and determined its quadrant, and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer