ADVERTISEMENT
ADVERTISEMENT

Ruby program to create Complex numbers from given imaginary parts

Ruby Example: Write a program to create Complex numbers from given imaginary parts.
Submitted by Nidhi, on December 11, 2021

Problem Solution:

In this program, we will create variables with some initial values. Then we will convert given numbers into a complex number using the i() function.

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.

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

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.