This is the program to check for the ‘Palindrome’ property of the given number. Palindrome is the instinct property of any literal segment, where the segment reads the same either from left to right or vice versa.
For example : 12321 and LEVEL are the palindromes as they reads same if we go from right to left also.
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.
A slight change in the code can check if the entered string is a palindrome.
long int n, num, rev = 0, dig;
printf(“\n\n\t ENTER A NUMBER…: “);
n = num;
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
if (n == rev)
printf(“\n\t GIVEN NUMBER IS A PALINDROME”);
printf(“\n\t GIVEN NUMBER NOT A PALINDROME”);
Download exe and source code here.