+ 1
Return true with palindromes
Trying to return true is number is palindrome in c++: bool isPalindrome(int x) { //complete the function //convert to string string stringOfX = to_string(x); char* array = new char [stringOfX.length() +1]; array[stringOfX.length]= "/0"; // add each char of stringOfX to array for (i =0; i< stringOfX.length(); i++){ array[i]= stringOfX[i]; } if(array[i] == strrev(array[i])){ return true; } else { return false; }
2 Respuestas
+ 3
First you can save your code on SL playground and code step by step, test and see how it works, similar to this example:
https://code.sololearn.com/ccf1IOVoECrX/?ref=app
+ 3
array[stringOfX.length() ] = '\0'; // is the correct way. You are missing () and use single quotes for characters. And use back slash \ , not /.
Loop variable i is not declared. Declare it as int i=0 or size_t i = 0;
For reverss comparision of enter string, there is no need subscript [i] so remove it.
( array == strrev(array) )
But strrev() is non-standard function of cstring of windows os supported. So may not work in all compilers. [ And not work in SL compiler].