Ruby program to subtract a number without using the minus (-) operator
# Ruby program to subtract the numbers
# without using the '-' operator
subt=0
num1=0
num2=0
print "Enter number1: ";
num1 = gets.chomp.to_i;
print "Enter number2: ";
num2 = gets.chomp.to_i;
subt = num1 + (~num2) + 1;
print "Subtraction is: ",subt;
Enter number1: 8
Enter number2: 3
Subtraction is: 5
Table of Contents