Q:

Write a Ruby program to compute the absolute difference between n and 33 and return double the absolute difference if n is over 33

0

Write a Ruby program to compute the absolute difference between n and 33 and return double the absolute difference if n is over 33.

All Answers

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

Ruby Code:

def diff_33(n)
    n > 33 ? ((n-33)*2).abs : (n-33).abs
end
print diff_33(47),"\n" 
print diff_33(17)

Output:

28
16

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