- 1

C++ Palindrome Help

I am doing the c++ course and i am stuck at the Palindrome numbers challenge. for some reason my code works for the visible test cases but fails for a hidden test case. Can anybody please tell me why :) ? #include <iostream> using namespace std; bool isPalindrome(int x) { int num; int rev; int dig; num = x; dig = num % 10; num = num / 10; rev = rev * 10 + dig; if(num!=0){ isPalindrome(num); } else{ if(rev == x){ 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; }

4th Feb 2021, 2:51 PM
Raphael
4 Réponses
0
thanks for the answers i managed to make it work
4th Feb 2021, 9:39 PM
Raphael