C-programming - To check whether the number is palindrome, C program to check palindrome

To check whether the number is palindrome

A palindromic number or numeral palindrome is a 'symmetrical' number like 1221, that remains the same when its digits are reversed.
To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not.


#include<stdio.h>
#include<conio.h>

main()
{
   int n, reverse = 0, temp;
 
   printf("Enter a number\n");
   scanf("%d",&n);
 
   temp = n;
 
   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }
 
   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);
 
   return 0;
}


In this program, we first get number to be checked from the user. This number is now copied to a new variable say temp. now reversing operations are performed on the value stored in temp. If the reversed number and the number entered by user are same then the number is a palindrome.

output


Enter a number
98789
98789 is a palindrome number.

The topic on C-programming - To check whether the number is palindrome is posted by - Maha

Hope you have enjoyed, C-programming - To check whether the number is palindromeThanks for your time

Tech Bluff