ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the imaginary part of the given complex number

Ruby Example: Write a program to get the imaginary part of the given complex number.
Submitted by Nidhi, on December 11, 2021

Problem Solution:

In this program, we will create variables for complex numbers and find the imaginary part of given complex numbers using the imaginary() function.

Program/Source Code:

The source code to get the imaginary part of the given complex number is given below. The given program is compiled and executed successfully.

# Ruby program to get the imaginary part 
# of the given complex number

num1 = Complex(200,10);
num2 = Complex(-1, 4);
num3 = Complex(23,45);

print "Num1: "  ,num1.imaginary();
print "\nNum2: ",num2.imaginary();
print "\nNum3: ",num3.imaginary();

Output:

Num1: 10
Num2: 4
Num3: 45

Explanation:

In the above program, we created three variables num1, num2, num3 initialized with complex numbers. Then we got the imaginary part of all complex numbers using the imaginary() function and printed the result.

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.