+ 2

Palindrome number

#include <iostream> using namespace std; int q,reminder,result =0; bool isPalindrome(int number) { q = number; while ( q != 0) { reminder = q % 10; result = (result*10)+reminder; q = q / 10; } } int main() { int n; cin >>n; if(result = n) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; } Hi Can any one help me ?! When i put a number that is not palindrome it saya it is palindrome Does anybody know where the problem is?

2nd Mar 2021, 2:54 PM
Mahla
Mahla - avatar
4 odpowiedzi
+ 1
"if(result=n)" //result is assigned always a number greater than 0 and so it is always true. Try input as 0 and it will output not palindrome.
2nd Mar 2021, 3:00 PM
Abhay
Abhay - avatar
+ 1
Mahla You are not using your function isPolindrome() anywhere.. And it is incomplete. It should be return a boolean value.. If input is same result then must return true else false. And call that function in main through if condition if( isPolindrome(n) ) { .. } With these changes ,it will complete your program fine.
2nd Mar 2021, 3:49 PM
Jayakrishna 🇮🇳
0
No it doesn't work :(
2nd Mar 2021, 3:12 PM
Mahla
Mahla - avatar
0
maybe convert it to array. idk how also. but i have an idea. store the reversed value in array. it's like you have an array of reversed and original value. then compare reversed == original value.
3rd Mar 2021, 3:23 AM
Hyperjones
Hyperjones - avatar