Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Numeric remainder() function

  • Last Updated : 06 Jan, 2020

The remainder() is an inbuilt method in Ruby returns the remainder when num1 is divided by num2.

Syntax: num1.remainder(num2)

Parameters: The function needs num1 and num2 which are to be divided.

Return Value: It returns the remainder.

Example 1:






# Ruby program for remainder()
# method in Numeric
  
# Initialize a number 
num1 = 17
num2 = 4
  
# Prints the remainder part
puts num1.remainder(num2)

Output:

1

Example 2:




# Ruby program for remainder()
# method in Numeric
  
# Initialize a number 
num1 = 12
num2 = 5
  
# Prints the remainder part
puts num1.remainder(num2)

Output:

2
My Personal Notes arrow_drop_up
Recommended Articles
Page :