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?
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-18.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics