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.
A number is a palindrome when we reverse the number and the reverse number is equal to the original number.
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();
}
}
}
Enter the No.: 14241
Entered Number is palindrome!
Comments