C#: Check whether two or more non-negative given integers have the same rightmost digit
Same Rightmost Digit in Two or More Integers
Write a C# Sharp program to check if two or more integers that are not negative have the same rightmost digit.
Visual Presentation:

Sample Solution:-
C# Sharp Code:
using System;
using System.Linq;
namespace exercises
{
// Class declaration
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Printing the results of the 'test' method with different integer values
Console.WriteLine(test(11, 21, 31)); // Output: True (since at least two numbers have the same last digit)
Console.WriteLine(test(11, 22, 31)); // Output: True (since at least two numbers have the same last digit)
Console.WriteLine(test(11, 22, 33)); // Output: False (since all numbers have different last digits)
Console.ReadLine(); // Keeping the console window open
}
// Method to check if at least two integers have the same last digit
public static bool test(int x, int y, int z)
{
// Returns true if x's last digit equals y's last digit or x's last digit equals z's last digit or y's last digit equals z's last digit
return x % 10 == y % 10 || x % 10 == z % 10 || y % 10 == z % 10;
}
}
}
Sample Output:
True True False
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C# program to check if the sum of digits of two integers ends in the same digit.
- Write a C# program to check whether the last digits of three integers form a palindrome sequence.
- Write a C# program to determine if any two integers end with digits that differ by 1.
- Write a C# program to check if all integers in a list share the same rightmost digit.
Go to:
PREV : Strict Increasing Order for Three Numbers.
NEXT : Check if One Integer 20 Less Than Another.
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.