Ruby Program to Get the Denominator From a Rational Number

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

Ruby program to get the denominator from a rational number

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

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

print "Num1 denominator: "  ,num1.denominator();
print "\nNum2 denominator: ",num2.denominator();
print "\nNum3 denominator: ",num3.denominator();
Num1 denominator: 1
Num2 denominator: 20
Num3 denominator: 1

Ranjith Kumar

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

Leave a Reply