Palindrome number program in c#

A palindrome number is a number such that if you reverse it, it will not change. The number should be remain same. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not.

Example of Palindrome numbers:

212, 121, 77077, 11611.

Program of palindrome number in c# console application


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n, reverse=0, temp;
                Console.WriteLine("ENTER A NUMBER TO CHECK PALINDROME OR NOT :- ");
                n = Convert.ToInt32(Console.ReadLine());
                temp = n;

                while (temp != 0)
                {
                    reverse = reverse * 10;
                    reverse = reverse + temp % 10;
                    temp = temp / 10;
                }
                if (n == reverse)
                {
                    Console.WriteLine("ENTER NUMBER IS PALINDROME.");
                }
                else
                {
                    Console.WriteLine("ENTER NUMBER IS NOT PALINDROME.");            
                }
                Console.ReadLine();
            }
        }
    }

Output

	
   ENTER A NUMBER TO CHECK PALINDROME OR NOT :- 777
   ENTER NUMBER IS PALINDROME.
           

Post Your Comment