0
Why program is not working correctly
#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int reverse=0,rem; while(x!=0){ rem=x%10; reverse =reverse*10 +rem; x/=10; } //cout<<reverse; if(x==reverse){ return true; } else{ return false ; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
3 Respuestas
+ 2
because you change x value to end at zero to get the reversed number, so when you compare x to reversed you compare 0 to reversed ^^
save your initial x in another variable, and compare it to reversed ;)
+ 1
Done :) @visph
0
you can also return reversed value and do comparison with return value and n ^^