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; }
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;
}
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;
}