Program of Palindrome number.

 What is Palindrome number  ?

A palindrome  number is a number  that remains same when digits are reversed. For example, the number 1551 is a palindrome number, but 1541 is not a palindrome number. 

* note : Negative number can not be palindrome.


Now here we understand the following program is palindrome or not.

#include<stdio.h>
int reverse(int);
int palindrome(int);
int main()
{
    int num;
    printf("Enter the number check
it isPalindrome or not : ");
    scanf("%d",&num);
    if(palindrome(num))
// 1 for true or 0 for false
    {
        printf("%d is palindrome.\n",num);
    }
    else
    {
        printf("%d is not palindrome.",num);
    }
    return 0;
}
int palindrome(int n)
{
    if(n==reverse(n)) // if reverse and
the number is equal then it isPalindrome.
        return 1;
    else
        return 0;
}
int reverse(int x)
{
    int rem,rev=0;
    while(x!=0)
    {
        rem=x%10;
        rev=rev*10+rem;
        x=x/10;
    }
    return rev;
}

Output :
Enter the number check it isPalindrome or not : 1221 1221 is palindrome.

So , above program find that Number is palindrome or not.

Comments

Popular posts from this blog

18 Amazing programs in C.