Code Golf: All +-*/ Combinations for 3 integers
- by Flash84x
Write a program that takes 3 integers separated by spaces and perform every single combination of addition, subtraction, multiplication and division operations possible and display the result with the operation combination used.
Example:
$./solution 1 2 3
Results in the following output
1+2+3 = 6
1-2-3 = -4
1*2*3 = 6
1/2/3 = 0 (integer answers only, round up at .5)
1*2-3 = -1
3*1+2 = 5
etc...
Order of operation rules apply, assume there will be no parenthesis used i.e. (3-1)*2 = 4 is not a combination, although you could implement this for "extra credit"
For results where a divide by 0 occurs simply return NaN