+ 1
Question is about creating a function in c++ but it is not working as expected
Function for palindrome numbers #include <iostream> using namespace std; bool isPalindrome(int x) { int reverse=0; int remainder; while(x!=0){ remainder=x%10; reverse=(reverse*10)+remainder; x/10; if(x==reverse){ return true; } else{ return false; } } } int main() { int n; cin >>n; if(isPalindrome(n)==0) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
3 Answers
+ 2
x/10 has no effect, store back result in x. like x=x/10;
First complete while loop, then after loop, compare in if block.
And after completion of while loop x is 0 so compare with passed original number so store it another variable for later reference..
Look out over braces start and end...
+ 1
Thankyou so much
0
I want you to figure out my mistake there is surely something im getting wrong