问题遇到的现象和发生背景
dotcpp中的一个习题,要求:给出一个不多于5位的整数,求出它是几位数
并分别输出每一位数字 。第二部卡住了。
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
int main()
{
int x,count;
count = 1;
scanf("%d", &x);
int n = x;
while (x / 10 > 0)
{
x = x / 10;
if (x >= 0)
{
count++;
}
}
printf("%d\n", count);
int number[5]={0};
int i;
for (i=0; i <= 4; i++)
{
number[i] = n % 10;
printf("%d ", number[i]);
}
return 0;
}
运行结果及报错内容
在number数组那里一直错误,不知道为什么?
如果用数组的话,那如何解决那?
谢谢!