Ruby Program to Get the Numerator From a Rational Number

You are currently viewing Ruby Program to Get the Numerator From a Rational Number

Ruby program to get the numerator from a rational number

# Ruby program to get the numerator 
# from a rational number

num1 = Rational(21, 7);
num2 = Rational(-7, 20);
num3 = Rational(21);

print "Num1 numerator: "  ,num1.numerator();
print "\nNum2 numerator: ",num2.numerator();
print "\nNum3 numerator: ",num3.numerator();
Num1 numerator: 3
Num2 numerator: -7
Num3 numerator: 21

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply