ADVERTISEMENT
ADVERTISEMENT

Ruby program to print the absolute value of Complex numbers

Ruby Example: Write a program to print the absolute value of Complex numbers.
Submitted by Nidhi, on December 11, 2021

Problem Solution:

In this program, we will create variables for complex numbers and print the absolute value of complex numbers using the abs() function.

Program/Source Code:

The source code to print the absolute value of Complex numbers is given below. The given program is compiled and executed successfully.

# Ruby program to print the 
# absolute value of Complex numbers

num1 = Complex(200);
num2 = Complex(-1, 4);
num3 = Complex('i');

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

Output:

Num1: 200
Num2: 4.123105625617661
Num3: 1

Explanation:

In the above program, we created three variable num1, num2, num3 initialized with complex numbers. Then we printed the absolute value of all created complex numbers using the abs() function.

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.