Open In App

Ruby | Numeric remainder() function

Last Updated : 19 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads