ADVERTISEMENT
ADVERTISEMENT

Ruby program to read coordinate points and determine its quadrant

Ruby Example: Write a program to read coordinate points and determine its quadrant.
Submitted by Nidhi, on November 30, 2021

Problem Solution:

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.

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  X, Y coordinate from the user and determined its quadrant, and printed the appropriate message.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.