Write a Swift program that accept two integer values and to test which value is nearest to the value 10, or return 0 if both integers have same distance from 10.
func close(_ a: Int, _ b: Int) -> Int {
if abs(10 - b) > abs(10 - a)
{
return a
}
else if abs(10 - b) < abs(10 - a)
{
return b
}
else
{
return 0
}
}
print(close(8, 13))
print(close(12, 7))
print(close(14, 6))