ADVERTISEMENT
ADVERTISEMENT

Ruby program to get the real part from a Complex number

Ruby Example: Write a program to get the real part from a Complex number.
Submitted by Nidhi, on December 14, 2021

Problem Solution:

In this program, we will create 2 variables and initialize them with some values. Then we will get the real part from a complex number using the built-in real() function.

Program/Source Code:

The source code to get the real part from a Complex number is given below. The given program is compiled and executed successfully.

# Ruby program to get the real part 
# from a Complex number

num1 = Complex(10, 23);
num2 = Complex(34, 45);

print "Real part num1: ",num1.real(),"\n";
print "Real part num2: ",num2.real(),"\n";

Output:

Real part num1: 10
Real part num2: 34

Explanation:

In the above program, we created two variables num1, num2 and initialized them with complex numbers. Then we used the real() function to get the real part from a complex number 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.