×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to demonstrate the abs2() function

Last Updated : December 15, 2025

Problem Solution

In this program, we will create two variables and initialize them with some values. Then we will use the abs2() function with created variables. The abs2() function returns the square of the given number.

Program/Source Code

The source code to demonstrate the abs2() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the abs2() function

num1 = Complex(2,3); 
num2 = -15;

print num1.abs2(),"\n";
print num2.abs2(),"\n";

Output

13
225

Explanation

In the above program, we created two variables num1, num2 and initialized them with some values. Then we used the abs2() function with both variables to get the square of numbers and printed the result.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.