×

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 find the largest number between two numbers using ternary operator

Last Updated : December 15, 2025

Problem Solution

In this program, we will read two integer numbers from the user. Then we will find the largest between two numbers using the ternary operator.

Program/Source Code

The source code to find the largest number between two numbers using the ternary operator is given below. The given program is compiled and executed successfully.

# Ruby program to find the largest number 
# between two numbers using ternary operator

print "Enter first number: ";
a = gets.chomp.to_i;  

print "Enter second number: ";
b = gets.chomp.to_i;  
  
largest=a>b ? a : b; 
        
print "Largest number is: ",largest;

Output

Enter first number: 19
Enter second number: 15
Largest number is: 19

Explanation

In the above program, we read two integer numbers from the user and found the largest number between them using the ternary operator, and printed the result.

Ruby Basic Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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