我写的判断回文数的代码,百位一下的能正确判断,但千位以上就不能了,肯定哪地方没设计好,请大虾帮忙改进
bool isPalindrome(int num) {
int n = 1, chushu = 10;
while (num / chushu != 0) {
chushu *= 10;
n++;
} //Find how large is a number
int division = (int) pow(10.0, n - 1);
for (int i = 0; i < n / 2; i++) {
int first = num / division;
int last = num % 10;
if (first != last) {
return false;
}
num = (int) ((num - first * division) / 10);
division /= 10;
}
return true;
}