回文数算法有问题,你的while循环都把数倒完了,你后面还在递归?正确算法是这样的,有帮助的话采纳一下哦!
int i = 0;
int isPalindrom(int n)
{
if(n==0)
return 1;
else
{
i *= 10;
i += n%10;
isPalindrom(n/10);
}
}
//主函数
void main()
{
int number;
scanf("%d",&number);
isPalindrom(number);
if(i==number)
{
printf("yes");
}
else
{
printf("no");
}
}
能用c++写一下解决方案吗
#include <iostream>
using namespace std;
int reserve(int a, int b = 0)
{
if (a == 0)
return b;
b = b * 10 + (a % 10);
return reserve(a / 10, b);
}
int main()
{
int a, b;
cin >> a;
b = reserve(a);
cout << b << endl;
if (a == b)
cout << "Y";
else
cout << "N";
}