×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to get the division and remainder using library function

Last Updated : December 15, 2025

Problem Solution

In this program, we will create 2 variables and initialize them with some values. Then we will get the division and remainder using library function divmod().

Program/Source Code

The source code to get the division and remainder using the library function is given below. The given program is compiled and executed successfully.

# Ruby program to get the division and remainder 
# using library function

num1 = 20
num2 = 3

print "Division and Remainder: ",num1.divmod(num2),"\n";

Output

Division and Remainder: [6, 2]

Explanation

In the above program, we created two variables num1, num2 and initialized 20, 3 respectively. Then we used the divmod() function to get division and remainder and printed the returned result.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.