Palindrome
A palindrome is anything that reads the same backward and forward. In other words after reversing any number, word or phrase if it remains the same as original then it is a palindrome.
Logic
To check whether a number is a palindrome number or not we have to reverse it first. After reversing it we compare the reversed number with the original number. If both the numbers are similar then it means the number we have is a palindrome number.
Program
#include <stdio.h> int main() { int num, temp, reverse = 0; // Take input from user printf("Enter any number : "); scanf("%d", &num); temp = num; while(temp != 0) { reverse = (reverse * 10) + (temp % 10); temp /= 10; } // Check for palindrome if(reverse == num) { printf("\n%d is a palindrome.", num); } else { printf("\n%d is not a palindrome.", num); } return 0; }
Output
Enter any number : 121
121 is a palindrome.