A palindrome is nothing but any word, number, sentence, or other sequence of characters that reads the same backward as forward.
In this programming, we are trying to enter a number from console, and assign that number to temp variable.
If number is greater than zero, apply the logic given below −
while(n>0){ r=n%10; sum=(sum*10)+r; n=n/10; }
If temp=sum, then the given number is a palindrome. Otherwise, it is not a palindrome.
Example
Following is the C program for verification of a value being palindrome −
#include<stdio.h> #include<conio.h> void main(){ int n, r, sum=0, temp; printf("Enter a number: "); scanf("%d",&n); temp=n; while(n>0){ r=n%10; sum=(sum*10)+r; n=n/10; } if(temp==sum) printf("It is a palindrome number!"); else printf("It is not a palindrome number!"); getch(); }
Output
When the above program is executed, it produces the following result −
12345 It is not a palindrome number