Write a Program in C to check whether a given number is palindrome or not.
The simplest method is to reverse the digits of the original number and check to see if the reversed number is equal to the original. This is not an efficient way of doing it but, for ints or long ints, it works well enough
What is the Logic : The program expects the user to enter the number to check if palindrome. The entered number is reversed and stored in another variable. Finally the reversed number is checked for equality with the entered number. If they are the same, then it is a palindrome.
Example:-555,1221,1333331 are palindrome
//Program to check whether a number is palindrome or not
long int n, num, rev = 0, dig;
printf(“nnt Enter a number:- “);
n = num;
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
if (n == rev)
printf(“nt It is palindrome”);
printf(“nt It is not palindrome”);