Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby Integer modulo() function with example

Improve Article
Save Article
Like Article
  • Last Updated : 03 Dec, 2020
Improve Article
Save Article
Like Article

The modulo function in Ruby returns the modulo value of a number by another number. 

Syntax: number1.modulo(number2)

Parameter: The function takes number1 and number2 whose modulo is returned.

Return Value: The function returns the modulo value of a number by another number. 

Example #1: 

Ruby




# Ruby program of modulo function
 
# Initializing the numbers
num1 = 10
num2 = 6
num3 = 13
num4 = 5
      
# Printing the modulo value
puts num1.modulo(num2)
puts num3.modulo(num4)

Output

4
3

Example #2: 

Ruby




# Ruby program of modulo function
 
# Initializing the numbers
num1 = 100
num2 = 17
num3 = 90
num4 = 29
     
# Printing the modulo value
puts num1.modulo(num2)
puts num3.modulo(num4)

Output

15
3

 

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!