07 判断回文数
问题描述:
设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数
代码实现:
int fun(int n) {
int rn = 0; // n逆置后的数
int temp = n;
// 对n进行逆置
while (temp) { // n不为0
rn = rn * 10 + temp % 10;
temp = temp / 10;
}
if (rn == n) {
return 1; // n是回文数
}
else {
return 0; // n非回文数
}
}