Swift Basic Programming Exercise: Test whether the last digit of the two given non-negative integer values are same or not
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?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics