Q:

Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum

0

Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def sum_double(x, y)
    x == y ? (x+y)*2 : x+y
end

print sum_double(5, 5),"\n" 
print sum_double(4, 5)
Output:
20
9

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now