ADVERTISEMENT
ADVERTISEMENT

Ruby program to find the largest number among three numbers using ternary operator

Ruby Example: Write a program to find the largest number among three numbers using ternary operator.
Submitted by Nidhi, on December 01, 2021

Problem Solution:

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

Program/Source Code:

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

# Ruby program to find the largest number 
# among three numbers using ternary operator

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

print "Enter second number: ";
b = gets.chomp.to_i;  

print "Enter third number: ";
c = gets.chomp.to_i;  

largest=a>b ? a>c ?a : c : b>c ? b : c;        
        
print "Largest number is: ",largest;

Output:

Enter first number: 12
Enter second number: 16
Enter third number: 19
Largest number is: 19

Explanation:

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

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.