The source code to create a Complex number from a given imaginary part is given below. The given program is compiled and executed successfully.
# Ruby program to create Complex number
# from given imaginary part
num1 = 10;
num2 = -20;
num3 = 30;
print "Num1: " ,num1.i();
print "\nNum2: ",num2.i();
print "\nNum3: ",num3.i();
Output:
Num1: 0+10i
Num2: 0-20i
Num3: 0+30i
Explanation:
In the above program, we created three variables num1, num2, num3 initialized with 10, -20, 30 respectively. Then we created complex numbers from given numbers where given numbers were used as imaginary parts using the i() function. After that, we printed the result.
Program/Source Code:
The source code to create a Complex number from a given imaginary part is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created three variables num1, num2, num3 initialized with 10, -20, 30 respectively. Then we created complex numbers from given numbers where given numbers were used as imaginary parts using the i() function. After that, we printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer