Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Numeric abs2() function

  • Last Updated : 19 Jan, 2021

The abs2() is an inbuilt method in Ruby returns the square of a number. 

Syntax: num.abs2

Parameters: The function needs the number whose square is to be returned. 

Return Value: It returns the square of a number.

Example 1:  



Ruby




# Ruby program for abs2() method in Numeric
 
# Initialize a number
num = -19
 
# Prints square of num
puts  num.abs2()

Output

361

Example 2

Ruby




# Ruby program for abs2() method in Numeric
 
# Initialize a number
num = 100
 
# Prints square of num
puts  num.abs2()

Output

10000

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :