Swift Basic Programming Exercise: Test whether the last digit of the two given non-negative integer values are same or not
Swift Basic Programming: Exercise-18 with Solution
Write a Swift program to test whether the last digit of the two given non-negative integer values are same or not.
Pictorial Presentation:
Sample Solution:
Swift Code:
func same_last_Digit(_ a: Int, _ b: Int) -> Bool {
guard a < 0, b < 0
else
{
if a % 10 == b % 10
{
return true
}
else
{
return false
}
}
return false
}
print(same_last_Digit(3, 13))
print(same_last_Digit(24, 4))
print(same_last_Digit(12, 24))
Sample Output:
true true false
Swift Programming Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Swift program that accept two positive integer values and test whether the larger value is in the range 20..30 inclusive, or return 0 if neither is in that range.
Next: Write a Swift program to convert the last three characters in upper case.
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