﻿ C# - An integer with two or more rightmost digits

# C#: Check whether two or more non-negative given integers have the same rightmost digit

## C# Sharp Basic Algorithm: Exercise-50 with Solution

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:

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.

﻿

Follow us on Facebook and Twitter for latest update.