A Program to Check a Palindrome Number
In this example, we are giving a program to check whether a number is palindrome or not. A number can be said palindrome if the reverse of the number is equal to the actual number.
Program to check palindrome:
#include <stdio.h>
int main() {
int n, reverse_number = 0, remainder, actual_number;
printf("Enter an integer: ");
scanf("%d", &n);
actual_number = n;
// reversed integer is stored in reverse_number
while (n != 0) {
remainder = n % 10;
reverse_number = reverse_number * 10 + remainder;
n /= 10;
}
// palindrome if actual_number and reverse_number are equal
if (actual_number == reverse_number)
printf("%d is a palindrome.", actual_number);
else
printf("%d is not a palindrome.", actual_number);
return 0;
}
Output:
Enter an integer: 3773 3773 is a palindrome.