Skip to content
Related Articles

Related Articles

Improve Article

Ruby Integer remainder() function with example

  • Last Updated : 03 Dec, 2020

The remainder() function in Ruby returns the remainder when two numbers are divided. 

Syntax: (number1).remainder(number2)

Parameter: The function takes two number number1 and number2 whose integer division and remainder is returned. 

Return Value: The function returns the remainder.

Example 1



Ruby




# Ruby program for remainder() function 
  
# Initializing the numbers
num1 = 18
num2 = 3
num3 = 13
num4 = 5
     
# Printing the modulo value
puts num1.remainder(num2)
puts num3.remainder(num4)

Output

0
3

Example 2

Ruby




# Ruby program for remainder() function 
  
# Initializing the numbers
num1 = 19
num2 = 4
num3 = 20
num4 = 5
  
# Printing the modulo value
puts num1.remainder(num2)
puts num3.remainder(num4)

Output

3
0

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :