Q:

Ruby program to get the real part from a Complex number

belongs to collection: Ruby Basic Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 num1num2 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to get the division and remainder usi... >>
<< Ruby program to check a given number is finite or ...