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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework