Q:

Ruby program to read coordinate points and determine its quadrant

belongs to collection: Ruby Basic Programs

0

In this program, we will read the X, Y coordinate points from the user. Then we will determine its quadrant and print the appropriate message.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

# 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  XY 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

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to extract the last two digits from t... >>
<< Ruby program to calculate the volume and area of S...