# Ruby program to get the numerator from a rational number

Ruby Example: Write a program to get the numerator from a rational number.
Submitted by Nidhi, on December 13, 2021

Problem Solution:

In this program, we will create 3 variables and initialize them with the rational number. Then we will use the numerator() function to get numerator from rational numbers.

Program/Source Code:

The source code to get the numerator from a rational number is given below. The given program is compiled and executed successfully.

```# 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();
```

Output:

```Num1 numerator: 3
Num2 numerator: -7
Num3 numerator: 21
```

Explanation:

In the above program, we created three variables and initialized them with the rational number. Then we used the numerator() function to get the numerator from rational numbers and printed the result.

What's New

Top Interview Coding Problems/Challenges!

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.