C# Sharp Basic Algorithm Exercises: Check whether two given non-negative integers have the same last digit
C# Sharp Basic Algorithm: Exercise-23 with Solution
Write a C# Sharp program to check whether two given non-negative integers have the same last digit.
Pictorial Presentation:
Sample Solution:-
C# Sharp Code:
using System;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(test(123, 456));
Console.WriteLine(test(12, 512));
Console.WriteLine(test(7, 87));
Console.WriteLine(test(12, 45));
Console.ReadLine();
}
public static bool test(int x, int y)
{
return Math.Abs(x % 10) == Math.Abs(y % 10);
}
}
}
Sample Output:
False True True False
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to check if a given string contains between 2 and 4 'z' character.
Next: Write a C# Sharp program to convert the last 3 characters of a given string in upper case.If the length of the string has less than 3 then uppercase all the characters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- 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