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:

  1. #include <stdio.h>
  2. int main() {
  3. int n, reverse_number = 0, remainder, actual_number;
  4. printf("Enter an integer: ");
  5. scanf("%d", &n);
  6. actual_number = n;
  7. // reversed integer is stored in reverse_number
  8. while (n != 0) {
  9. remainder = n % 10;
  10. reverse_number = reverse_number * 10 + remainder;
  11. n /= 10;
  12. }
  13. // palindrome if actual_number and reverse_number are equal
  14. if (actual_number == reverse_number)
  15. printf("%d is a palindrome.", actual_number);
  16. else
  17. printf("%d is not a palindrome.", actual_number);
  18. return 0;
  19. }

Output:

Enter an integer: 3773
3773 is a palindrome.