Palindrom numbers | Sololearn: Learn to code for FREE!

+1

Palindrom numbers

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns true if a given number is a palindrome, and false, if it is not. Complete the given function, so that the code in main works and results in the expected output. Sample Input: 13431 Sample Output: 13431 is a palindrome

2/2/2022 2:19:28 PM

Bilal Khan

8 Answers

New Answer

+1

Ani Jona 🕊 your link dosen't work bro..

+3

One "x%10" does not a reverse of a number make. If you want to work with numbers - and it seems the task asks you to -, then you need to collect the digits that you split off using the modulo operator in another variable. The result needs to be compared to the original value, thus x needs to be retained. So, set int y = x; In the while loop, collect the digits in rev by setting rev initially to zero, and multiply by ten in each iteration to shift the digits one position to the left before adding another digit: rev *= 10; rev += x % 10; x /= 10; until x == 0. Then "return y == rev;"

+2

Its my code #include <iostream> using namespace std; bool isPalindrome(int x) { int rev; if(x>10){ while(x>=0){ //complete the function rev=x%10; x=x/10; if(rev==x){ return true; }else if(x==0){ return false; } } }else{ return true; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

+1

https://code.sololearn.com/c4eUnaD4ecOa solution

+1

What link? You probably meant to refer to fajnah6 ? 🙃

+1

Oh yeh fajnah6 your link dosen't work?

+1

I am also now confuse in pallindrom any one can answer it clear ?

0

yea i know, i ment to delete something else and acidentally deleted this 😓