求逆序数
#include <stdio.h>
# include <math.h>
unsigned int reverse( unsigned int number );
int main()
{
unsigned int n;
scanf("%u", &n);
printf("%u\n", reverse(n));
return 0;
}
函数实现:
unsigned int reverse( unsigned int number )
{
int t=0;
while(number)
{
t=t*10+number%10;
number=number/10;
}
return t;
}
错误点:
开始的时候我先
if (number<9)
return number;
但是其实
int t;
t=t*10+number%10;
number=number /10;
用上面这个循环即使是一位数,也可以正确输出;