How to test palindrome in c++






How to test a number is palindrome or not in c++

#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 a palindrome";
    else
       cout << num << " is not a 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;
}




Algorithm:
**


No comments: