Swift Basic Programming Exercise: Check if a given non-negative number is a multiple of 3 or a multiple of 5
Swift Basic Programming: Exercise-9 with Solution
Write a Swift program to check if a given non-negative number is a multiple of 3 or a multiple of 5.
Pictorial Presentation:
Sample Solution:
Swift Code:
func test35(num: Int) -> Bool {
if num % 3 == 0 || num % 5 == 0 {
return true
} else {
return false
}
}
print(test35(num: 33))
print(test35(num: 100))
print(test35(num: 15))
print(test35(num: 17))
Sample Output:
true true true false
Swift Programming Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Swift program to add the last character (given string) at the front and back of a given string.
Next: Write a Swift program to take the first two characters from a given string and create a new string with the two characters added at both the front and back.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/swift-programming-exercises/basic/swift-basic-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics