Write a Swift program to compute and return the absolute difference of n and 51, if n is over 51 return double the absolute difference

bookmark

func diff_51(x: Int) -> Int {
    if x > 51 
     {
        return (x - 51) * 2
     } 
    else
     {
        return 51 - x
     }
}

print(diff_51(x: 45))
print(diff_51(x: 61))
print(diff_51(x: 21))

 

Output:

6
20
30