Palindrome Numbers
A palindromic number is a number (such as 626) that remains the same when its digits are reversed.
Write a function that returns true if a given number is a palindrome, and false, if it is not.
Complete the given function, so that the code in main works and results in the expected output.
Sample Input:
13431
Sample Output:
13431 is a palindrome
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
int a = x, h = 1;
if (a < 0) return false;
while (a / h >= 10) {
h = h * 10;
}
while (a > 0){
if (a /h != a % 10) return false;
a = a % h;
a = a/ 10;
h = h / 100;
}
return true;
}
int main() {
int n;
cin >>n;
if(isPalindrome(n)) {
cout <<n<<" is a palindrome";
}
else {
cout << n<<" is NOT a palindrome";
}
return 0;
}