Skip to content
Home » How to check whether a number is Palindrome or not in C

How to check whether a number is Palindrome or not in C

A number is said to be Palindrome only if the number after reversing is same as given digit. For example, if we consider the number 15651 after reversing the number it will be same hence it is palindrome number. Here is the example of program to check whether a number is Palindrome or not.

#include <stdio.h>
int main() 
{
    int r,rev,n,temp;
    printf("Enter number:");
    scanf("%d",&n);
    temp=n;//storing in temp becoz after operations n will be changed
    while(n>0)    
    {
        r=n%10;    
        rev=(rev*10)+r;    
        n=n/10;    
    }//reversing a number
    if(temp==rev)//comparing with reversed
    {
        printf("The %d is Palindrome",temp);
    }
    else
    {
        printf("The %d is not Palindrome",temp);
    }
}

Enter number:15651
The 15651 is Palindrome

Enter number:1546
The 1546 is not Palindrome

Also Read:

Reversing a number in C