0

Palindrome Number

Hi , guys ! My code seems to not be correct enough to unlock the third hidden test . Can someone please help . #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function // calculate and store the number of digits in the number input int Total = 0 ; int count = 0 ; int digit = x ; int * arrDigits ; // count the number of digits arrDigits = new int [count ] ; while ( x > 0 ) { digit = x % 10 ; count ++ ; arrDigits[count] = digit ; x= x/10 ; } // store the digits in array respectively Total = count ; count += 1 ; // check if the number remains the same when reversed for ( int a =0 ; a <= Total ; a ++) { int Arrdigit2 = arrDigits[count --] ; int Arrdigit1 = arrDigits[a] ; if (Arrdigit2 == 0 || Arrdigit1 ==0) { continue ; } if ( Arrdigit1 == Arrdigit2 ) { 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; }

7th Jan 2022, 5:35 PM
Celia
Celia - avatar
2 Answers
0
When either digit is zero, you just continue the loop and don't compare them. You return prematurely when you encounter the first digit that matches.
10th Jan 2022, 2:04 AM
Brian
Brian - avatar
0
Please link your code and tag the relevant programming language!
7th Jan 2022, 5:41 PM
Lisa
Lisa - avatar