Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

03 June 2012

.NET Program to check whether the given number is palindrome number or not


In this snippet we will write a program to check whether the given number is palindrome number or not.

What is palindrome Number?
Palindrome number is a number that remains the same when its digits are reversed
Example: Number 151 is a palindrome number.
Number 152 - it not a palindrome number.

Snippet:
class PalindromeNumber
    {
        public static void Main()
        {
            Console.WriteLine("********** Palindrome Number Check Example ********");
            Console.WriteLine("Enter Number to Want to check");
            int numberToCheck = int.Parse(Console.ReadLine());
            int lenthOfNumber = numberToCheck.ToString().Length;
            double reminder = 0;
            double sum = 0;
            int tempNo = numberToCheck;
            while (tempNo > 0)
            {
                reminder = tempNo % 10;
                sum = sum *10 + reminder ;
                tempNo = tempNo / 10;
            }
            if (sum == numberToCheck)
            {
                Console.WriteLine("The given Number {0} is a Palindrome Number", numberToCheck);
            }
            else
            {
                Console.WriteLine("The given Number {0} is NOT a Palindrome Number", numberToCheck);
            }
            Console.ReadLine();

        }
    }

Output:
 Example : Input =151 (palindrome Number)






 Example : Input =152 (not a palindrome Number)
 

Some of palindrome numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161.......



0 Comments:

Post a Comment