整数逆序
-
整数分解
- 一个整数是由意味至多位数字组成,如何分解出整数的各个位上的数字,然后加以计算
- 对一个整数坐%10的操作,就得到它的各位数;
- 对一个整数做/10的操作,就去掉了它的个位数;
- 然后再对2的结果做%10,就得到原来数的十位数了;
- 以此类推
代码
#include<stdio.h>
int main()
{
int x;
// scanf("%d",&x);
x=12345;
int digit;
int ret = 0;
while(x>0) {
digit = x%10;//取出个位数
// printf("%d\n",digit);
ret = ret*10 + digit;//将最右边的数移动左边
printf("x=%d,digit=%d,ret=%d\n",x,digit,ret);
x/=10;//将个位数去掉
}
printf("%d,ret");
return 0;
}