Q:

Write a C# Sharp program to check whether a given integer is a palindrome integer or not. Return true if the number is palindrome otherwise return false

0

 Write a C# Sharp program to check whether a given integer is a palindrome integer or not. Return true if the number is palindrome otherwise return false. 
Expected Output:
Original integer value: 123456
Check the said number is a palindrome number or not:
False
Original integer value: 16461
Check the said number is a palindrome number or not:
True
Original integer value: -121
Check the said number is a palindrome number or not:
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) {
      int n;
      n = 123456;
      Console.WriteLine("Original integer value: " + n);
      Console.WriteLine("Check the said number is a palindrome number or not:");
      Console.WriteLine(test_is_Palindrome(n));
      n = 16461;
      Console.WriteLine("Original integer value: " + n);
      Console.WriteLine("Check the said number is a palindrome number or not:");
      Console.WriteLine(test_is_Palindrome(n));
      n = -121;
      Console.WriteLine("Original integer value: " + n);
      Console.WriteLine("Check the said number is a palindrome number or not:");
      Console.WriteLine(test_is_Palindrome(n));
      }
        public static bool test_is_Palindrome(int a)
        {
            if (a < 0) { return false; }
            if (a < 10) { return true; }
            var temp = a;
            var b = 0;
            var digit = 0;
            while (temp != 0)
            {
                digit = temp % 10;
                b = b * 10 + digit;
                temp /= 10;
            }
            return a == b;
        }
    }
  }

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