0

В чём собственно ошибка?

#include <iostream> #include <cmath> using namespace std; bool isPalindrome(int x) { //завершите функцию int a,b,c,n=0; a=x; do { c = a % 10; b = (b * 10) + c; n++; a=a/10; } while (a != 0); b=(b*10)+(x/pow(10,n)); if (x==b){ return true ; } else { return false ;} } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

5th Nov 2021, 9:49 AM
Alexander
Alexander - avatar
2 Antworten
+ 2
#include <iostream> using namespace std; bool isPalindrome(int x) { int num, rem, rev=0; num=x; while(x != 0) { rem = x%10; rev= rev*10 + rem; x /= 10; } if (rev==num) { return true; } else { return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
6th Nov 2021, 4:23 AM
Jocelyn
Jocelyn - avatar
0
Correct code) #include <iostream> #include <cmath> using namespace std; bool isPalindrome(int x) { //завершите функцию int a,b=0,c; a=x; do { c = a % 10; b = (b * 10) + c; a=a/10; } while (a != 0); if (x==b){ return true ; } else { return false ;} } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
5th Nov 2021, 11:46 AM
Alexander
Alexander - avatar