Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Swift Basic Programming Exercise: Return true if either of two given integers is in the range 10..30 inclusive

Swift Basic Programming: Exercise-12 with Solution

Write a Swift program that return true if either of two given integers is in the range 10..30 inclusive.

Pictorial Presentation:

Swift Basic Programming Exercise: Return true if either of two given integers is in the range 10..30 inclusive.

Sample Solution:

Swift Code:

func in1030(a: Int, b: Int) -> Bool {
    if a >= 10 && a <= 30
    {
        return true
    } 
    else if b >= 10 && b <= 30
    {
        return true
    }
    else 
    {
        return false
    }
}
print(in1030(a: 15, b: 40))
print(in1030(a: 55, b: 9))
print(in1030(a: 11, b: 25))

Sample Output:

true
false
true

Swift Programming Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Swift program to test a given string whether it starts with "Is". Return true or false.
Next: Write a Swift program to check if a given string begins with "fix", except the 'f' can be any character or number.

What is the difficulty level of this exercise?