Write a Swift program that accept 2 integer values and return true if one of them is 30 or if their sum is 30

Topics

Introduction

I have used Swift for windows 1.9 for debugging purpose. But you can use any Swift programming language compiler as per your availability.

func findandtotaltwenty(num1: Int, num2: Int) -> Bool {
    if num1 + num2 == 30 || num1 == 30 || num2 == 30
 
    {
        return true
    }
    else
    {
        return false
    }
}
print(findandtotaltwenty(num1: 10, num2: 30))
print(findandtotaltwenty(num1: 15, num2: 15))
print(findandtotaltwenty(num1: 39, num2: 15))

Result

Leave a Comment