0

Palindrome Help

What am I doing wrong here? #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int digit; int rev=0; while(x!=0){ digit=x%10; rev=(rev*10)+digit; x/=10; } if(x==rev) 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; }

19th Apr 2022, 3:06 AM
Stephanie
2 ответов
+ 4
Stephanie You are changing original value so x would be 0 Store x in a temp variable before using it then compare temp variable with rev also you missed return in else part if (temp == rev) return true; else return false; OR return (temp == rev);
19th Apr 2022, 3:20 AM
A͢J
A͢J - avatar
+ 2
Thank you!
19th Apr 2022, 3:41 AM
Stephanie