+ 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

2nd Feb 2022, 2:19 PM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
8 Answers
+ 1
Ani Jona 🕊 your link dosen't work bro..
10th Feb 2022, 10:12 AM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
+ 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;"
2nd Feb 2022, 2:49 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 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; }
2nd Feb 2022, 2:20 PM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
2nd Feb 2022, 4:39 PM
fajnah6
+ 1
What link? You probably meant to refer to fajnah6 ? 🙃
10th Feb 2022, 10:48 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Oh yeh fajnah6 your link dosen't work?
10th Feb 2022, 11:36 AM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
+ 1
I am also now confuse in pallindrom any one can answer it clear ?
10th Feb 2022, 11:39 AM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
0
yea i know, i ment to delete something else and acidentally deleted this 😓
10th Feb 2022, 6:55 PM
fajnah6