C# Program to Reverse a Number & Check if it is a Palindrome
C# Program to find whether the Number is Palindrome or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using System; namespace NumberPalindrome { class Program { static void Main(string[] args) { int num, rem, sum = 0, temp; //clrscr(); Console.WriteLine("\n >>>> To Find a Number is Palindrome or not <<<< "); Console.Write("\n Enter a number: "); num = Convert.ToInt32(Console.ReadLine()); temp = num; while (Convert.ToBoolean(num)) { 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) //checking whether the reversed number is equal to entered number { Console.WriteLine("\n Number is Palindrome \n\n"); } else { Console.WriteLine("\n Number is not a palindrome \n\n"); } Console.ReadLine(); } } } |
Output 1:
Output 2:
For C Program: C Program To Find The Number Palindrome or Not