+ 1

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that return

My trying #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int n,s=0,r; x=n; while(n!=0) { r=n%10; s=s*10+r; n=n/10; } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

7th Apr 2021, 4:42 AM
Utkarsh Tripathi
Utkarsh Tripathi - avatar
4 Answers
+ 3
Inside isPalindrome function: Change `x = n` to `n = x` this is because you use <n> in reversing process. return `( s == x )` from isPalindrome, after the loop body. Add a closing curly bracket } after return statement cause it's missing.
7th Apr 2021, 5:20 AM
Ipang
+ 2
Try it, and test it, Thank me later ... 👌
7th Apr 2021, 5:31 AM
Ipang
+ 1
Thanks
7th Apr 2021, 5:21 AM
Utkarsh Tripathi
Utkarsh Tripathi - avatar
+ 1
Ok
7th Apr 2021, 5:32 AM
Utkarsh Tripathi
Utkarsh Tripathi - avatar