Minimum value (ruby edition)
Find the smallest value in Ruby
Value to be entered
n_1
n_2
n_3
n_4
n_5
Expected output
Outputs the smallest number among n_1, n_2, n_3, n_4, n_5
conditions
The following conditions are met in all test cases.
・ 1 ≤ n_1, n_2, n_3, n_4, n_5 ≤ 100
Input example 1
10
12
4
8
46
Output example 1
4
Answer
python
n_1 = gets.to_i
n_2 = gets.to_i
n_3 = gets.to_i
n_4 = gets.to_i
n_5 = gets.to_i
result = [n_1, n_2, n_3, n_4, n_5 ]
puts result.min
Output result
4
Commentary
Substitute input examples 10 to 46 into variables n_1 to n_5 using gets.to_i
Next, put the numerical values from n_1 to n_5 into the array and assign it to the variable called result.
Finally, puts outputs the result, but since we want to find only the minimum number, we output it using min.
The maximum value can be output by setting min to max.
If you want to output only n_3, you can output the value of n_3 by setting puts result [2].
that's all