Advertisement
kilya

IsPalindrome

Jun 25th, 2020
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IsPalindrome
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Enter your number :");
  10.             int x = int.Parse(Console.ReadLine());
  11.             Console.WriteLine(IsPalindrome(x));
  12.             Console.ReadKey();
  13.         }
  14.        
  15.         static bool IsPalindrome(int x)
  16.         {
  17.             if (x <= 0 || (x % 10 == 0 && x != 0))
  18.                 return false;
  19.  
  20.             int reverse = 0;
  21.             while (x > reverse)
  22.             {
  23.                 reverse = reverse * 10 + x % 10;
  24.                 x /= 10;
  25.             }
  26.             return x == reverse || x == reverse / 10;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement