How to find the Maximum of Three Numbers in Ruby


How to find the Maximum of Three Numbers in Ruby ?

Answer

To find the maximum of three numbers in Ruby, you can use the `max` method.



✐ Examples

1 Find Maximum of Three Numbers

In this example,

  1. We declare three variables a, b, and c with the numbers to compare.
  2. We use the `max` method to compare the numbers and get the maximum.

Ruby Program

a = 5
b = 8
c = 3
max = [a, b, c].max
puts "Maximum of three numbers is: #{max}"

Output

Maximum of three numbers is: 8

Summary

In this tutorial, we learned How to find the Maximum of Three Numbers in Ruby language with well detailed examples.




More Ruby Comparison Operations Tutorials

  1. How to find the Maximum of Two Numbers in Ruby ?
  2. How to find the Minimum of Two Numbers in Ruby ?
  3. How to find the Maximum of Three Numbers in Ruby ?
  4. How to find the Minimum of Three Numbers in Ruby ?