Write a Swift program to accept two integer values and return true if one is negative and one is positive. Return true only if both are negative.

bookmark

func test_num(x: Int, y: Int) -> Bool {
    if x > 0 && y < 0 
    {
        return true
    }
    else if x < 0 && y > 0 
    {
        return true
    } 
    else if x < 0 && y < 0 
    {
        return true
    } 
    else
    {
        return false
    }
}

print(test_num(x:12, y:-5))
print(test_num(x:-12, y:5))
print(test_num(x:-12, y:-5))
print(test_num(x:12, y:5))

 

Output:

 

true
true
true
false