The imaginary() is an inbuilt method in Ruby returns the imaginary part of the given number.
Syntax: num.imaginary()
Parameters: The function needs a number whose imaginary part is to be returned.
Return Value: It returns the imaginary part.
Example 1:
# Ruby program for imaginary()
# method in Numeric
# Initialize a number
num1 = Complex(10, 9)
# Prints Imaginary number
puts num1.imaginary()
|
Output:
9
Example 2:
# Ruby program for imaginary()
# method in Numeric
# Initialize a number
num1 = Complex(10, 0)
# Prints Imaginary number
puts num1.imaginary()
|
Output:
0
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Jan, 2020
Like Article
Save Article