C Programming

C Program – Check a number is Palindrome or not

C Program to check a given number is palindrome or not.

Number is Palindrome or not ?

Palindrome.c
#include<stdio.h> 
long int reverse(long int n); 
int isPalindrome(long int num); 
int main(void) 
{ 
    long int num; 
    printf("Enter any number : "); 
    scanf("%ld",&num); 
    if(isPalindrome(num)) 
        printf("Given Number is a palindrome\n"); 
    else 
        printf("Given Number is not a palindrome\n"); 
    return 0; 
} 
int isPalindrome(long int num) 
{ 
    if(num==reverse(num)) 
        return 1; 
    return 0; 
} 
long int reverse(long int n) 
{ 
    long int rev=0; 
    do 
    { 
        rev=rev*10+n%10; 
        n/=10; 
    }while(n>0); 
    return rev; 
}

Output:

Terminal
Enter any number : 568956
Given Number is not a palindrome

Enter any number : 56465
Given Number is a palindrome

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment