w3resource
C# Sharp Programming Exercises

C# Sharp Basic Algorithm Exercises: Check if 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 if two given non-negative integers have the same last digit.

Pictorial Presentation:

C# Sharp: Basic Algorithm Exercises - Check if two given non-negative integers have the same last digit

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: Flowchart: Check if two given non-negative integers have the same last digit

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?



New Content: Composer: Dependency manager for PHP, R Programming