不知道为什么输出0000,帮忙看一下,谢谢
目的,输入一个整数,从最高位开始顺序输出
计算位数的时候,x 最终为 0 了,后面就是输出0。修改如下,供参考对照:
#include <stdio.h>
#include <math.h>
int main()
{
int x, y, count = 0;
printf("请输入一个整数:\n");
scanf_s("%d", &x);
if (x < 0) x = -x;
y = x;
do {
x /= 10;
count++;
} while (x != 0);
for (count--; count >= 0; count--)
{
x = (int)pow(10, count);
printf("%d\n", y / x);
y = y % x;
}
return 0;
}
for的第一个参数,count=count-1