+ 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; }
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.
+ 2
Try it, and test it,
Thank me later ... đ
+ 1
Thanks
+ 1
Ok