Ruby program to print average of given 3 numbers

Views: 25   

Following program shows you how to print average of given 3 numbers.
In this program we get inputs from user and calculate average of given 3 numbers using following formula
Average of given 3 numbers = (input1 + input2 + input3) / 3

 puts "Enter first number:"
 input1 = Integer(gets.chomp)
 puts "Enter second number:"
 input2 = Integer(gets.chomp)
 puts "Enter third number:"
 input3 = Integer(gets.chomp)
 result = (input1 + input2 + input3) / 3
 puts "The average of three numbers: #{result}"


Enter first number:
Enter second number:
Enter third number:
The average of three numbers: 20
On By