Ruby program to add two integer numbers

bookmark

=begin 
Ruby program to add two numbers.
=end

# input the numbers and converting 
# them into integer 
puts "Enter first value: "
num1=gets.chomp.to_i
puts "Enter second value: "
num2=gets.chomp.to_i

# finding sum 
sum=num1+num2

# printing the result
puts "The sum is #{sum}"

 


Output:

First run:
Enter first value:
123
Enter second value:
456
The sum is 579

Second run:
Enter first value:
-120
Enter second value:
20
The sum is -100