;

C# Program to check whether number is palindrome or not


Tutorialsrack 23/02/2019 C# Programs

What is Palindrome?

A palindrome is a word, number, phrase, or other sequences of characters which reads the same backward as forward, such as civic or rotator or the number 14241. 

C# Program to check whether a number is palindrome or not

A number is a palindrome when we reverse the number and the reverse number is equal to the original number.

Example - C# Program to check whether a number is palindrome or not
using System;

namespace PalindromeORnot
{
    class Program
    {
        static void Main(string[] args)
        {
            int Number,OriginalNumber,ReversedNumber=0,Remainder=0;
            Console.Write("Enter the No.: ");
            Number = Convert.ToInt32(Console.ReadLine());

            OriginalNumber = Number;

            while (Number > 0)
            {
                Remainder = Number % 10;
                ReversedNumber = ReversedNumber * 10 + Remainder;
                Number /= 10;
            }
            if (ReversedNumber == OriginalNumber)
            {
                Console.WriteLine("Entered Number is palindrome!");
            }
            else
            {
                Console.WriteLine("Entered Number is not palindrome!");
            }

            Console.ReadKey();
        }
    }
}
Output

Enter the No.: 14241

Entered Number is palindrome!

 


Related Posts



Comments

Recent Posts
Tags