【编程】从键盘输入一个四位正整数。首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字

#include <stdio.h>
#include <stdlib.h>

void main ()
{
int a,b,c,d,x;

printf("请输入一个四位正整数:");
scanf("&d",x);

if (x > 9999 || x < 1000)
{
printf("Input Error!\n");
exit(-1);
}
else
{
a=x / 1000;
b=x / 100 % 10;
c=x / 10 % 10;
d=x % 10;
}

printf("The Inverse Number is ");
scanf("%d",a + b * 10 + c * 100 + d * 1000);

}
这有什么错?为什么一直都是“Input Error!”?

两个地方错了。

第一,scanf()读入的应为变量的地址,所以

scanf("&d",x);

应该是

scanf("%d",&x)        //要用&x,否则程序出错


第二,

scanf("%d",a + b * 10 + c * 100 + d * 1000);

应该是

printf("%d",a + b * 10 + c * 100 + d * 1000);

温馨提示:答案为网友推荐,仅供参考