Q:

Write a C# Sharp program to check if two given non-negative integers have the same last digit

0

Write a C# Sharp program to check if two given non-negative integers have the same last digit

Sample Output:

False
True
True
False

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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);
        }
  }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now