+ 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; }

16th Apr 2022, 11:53 AM
Ashas Shahid
Ashas Shahid - avatar
3 odpowiedzi
+ 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...
16th Apr 2022, 12:02 PM
Jayakrishna 🇮🇳
+ 1
Thankyou so much
16th Apr 2022, 12:30 PM
Ashas Shahid
Ashas Shahid - avatar
0
I want you to figure out my mistake there is surely something im getting wrong
16th Apr 2022, 11:54 AM
Ashas Shahid
Ashas Shahid - avatar