Program To
Check The Number Is Palindrome Or Not in C#
A Palindromic number or numeral Palindrome is a number, which remains the same when its digits are reversed. Like 16461,
private static void
NumberPalindrome() { int num,
rem, sum = 0, temp;
Console.Write("\n Enter a number: "); num =
Convert.ToInt32(Console.ReadLine()); temp
= num; while (num
> 0) {
rem = num % 10; //for getting remainder by dividing with 10
num = num / 10; //for getting quotient by dividing with 10
sum = sum * 10 + rem; /*multiplying
the sum with 10 and adding
remainder*/ }
Console.WriteLine("\n The Reversed Number is: {0} \n",
sum); if (temp
== sum) {
Console.WriteLine("\n Number is Palindrome \n\n"); } else {
Console.WriteLine("\n Number is not a palindrome \n\n"); }
Console.ReadLine(); } |
Output
EmoticonEmoticon