palindrome check in c++

Check the no is palindrome or not.
How to test a number is palindrome or not in c++
 Write a program to check no is palindrome or not.


#include<iostream>

int checkPalindrome(int);
int main(){
    int num,sum;

    cout << "Enter a number: ";
    cin >> num;

    sum = checkPalindrome(num);

    if(num==sum)
         cout << num << " is palindrome";
    else
       cout << num << " is not palindrome";

    return 0;
}

int checkPalindrome(int num){

    static int sum=0,r;

    if(num!=0){
         r=num%10;
         sum=sum*10+r;
         checkPalindrome(num/10);
    }

    return sum;
}

 

No comments:

Post a Comment