- 2
Please what is the error in this
Palindrome numbers https://code.sololearn.com/cBVt2i2R88rA/?ref=app
13 odpowiedzi
+ 7
A͢J Thanks it works now
+ 3
First tell us where we have to see error?
+ 3
A͢J Sorry my bad
+ 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;
}
+ 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.
+ 1
It works fine brother
+ 1
New here... Would like to link up with anybody that could be of help
0
Where's the error?
0
Now there is no error
It working fine
0
There is not error in this code.
- 2
B