MuffinMonster

Class Task 4#

Sep 29th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine(">>>> Checking if the number is Palindrome <<<<");
  14.             Console.WriteLine(">>>>>> Enter a number: <<<<<<");
  15.             int num, temp, sum = 0, rem, y, x;
  16.             num = int.Parse(Console.ReadLine());
  17.             temp = num;
  18.             y = num;
  19.             x = 0;
  20.             while (y > 0)
  21.             {
  22.                 y = y / 10;
  23.                 x++;
  24.             }
  25.             while (x > 0)
  26.             {
  27.                 rem = num % 10;  
  28.                 num = num / 10;
  29.                 sum = sum * 10 + rem;
  30.                 x--;
  31.             }
  32.             if (temp == sum)
  33.             {
  34.                 Console.WriteLine("Number is Palindrome");
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine("Number is not a palindrome");
  39.             }
  40.             Console.ReadLine();
  41.             Console.ReadKey();
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment