- 2

Please what is the error in this

Palindrome numbers https://code.sololearn.com/cBVt2i2R88rA/?ref=app

12th Apr 2022, 6:09 AM
Olufikayomi Jetawo
11 Respostas
+ 7
AÍąJ Thanks it works now
12th Apr 2022, 6:28 AM
Olufikayomi Jetawo
+ 3
First tell us where we have to see error?
12th Apr 2022, 6:13 AM
AÍąJ
AÍąJ - avatar
+ 3
AÍąJ Sorry my bad
12th Apr 2022, 6:17 AM
Olufikayomi Jetawo
+ 3
Olufikayomi Jetawo You are changing the value of original variable x which would be 0 So Store x in a temp variable and compare this temp variable to rev variable int temp = x; while(x>0){ rem = x%10; rev = (rev * 10) + rem; x = x/10; } if (temp == rev){ return true; } else { return false; }
12th Apr 2022, 6:24 AM
AÍąJ
AÍąJ - avatar
+ 1
My variation of solution: #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int rev = 0,rem; int temp=x; if(x<10) return true; else { while(x>0){ rem = x%10; rev = (rev * 10) + rem; x = x/10; } if (temp == rev){ return true; } } return false; } int main() { int n=121; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; } You haven't taken that a single digit is a palindrom.
13th Apr 2022, 3:28 PM
TeaserCode
+ 1
It works fine brother
13th Apr 2022, 3:32 PM
Harsh Kanjiya
Harsh Kanjiya - avatar
+ 1
New here... Would like to link up with anybody that could be of help
13th Apr 2022, 9:52 PM
Fredrick George
Fredrick George - avatar
0
Where's the error?
13th Apr 2022, 12:34 PM
Leonardo Joanes da Silva
Leonardo Joanes da Silva - avatar
0
Now there is no error It working fine
13th Apr 2022, 12:53 PM
NARPAT AANJANA
NARPAT AANJANA - avatar
0
There is not error in this code.
13th Apr 2022, 5:58 PM
Daniil
- 2
B
13th Apr 2022, 9:10 AM
Douaa Chaib