【编程】从键盘输入一个四位正整数.首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字#include #include void main (){\x09int a,b,c,d,x;\x09printf("请输入一个四位正整数:");\x09scanf("&d",x);\

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 22:24:31
【编程】从键盘输入一个四位正整数.首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字#include #include void main (){\x09int a,b,c,d,x;\x09printf(

【编程】从键盘输入一个四位正整数.首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字#include #include void main (){\x09int a,b,c,d,x;\x09printf("请输入一个四位正整数:");\x09scanf("&d",x);\
【编程】从键盘输入一个四位正整数.首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字
#include
#include
void main ()
{
\x09int a,b,c,d,x;
\x09printf("请输入一个四位正整数:");
\x09scanf("&d",x);
\x09if (x > 9999 || x < 1000)
{
\x09 printf("Input Error!\n");
\x09 exit(-1);
\x09}
\x09else
\x09{
\x09\x09a=x / 1000;
\x09\x09b=x / 100 % 10;
\x09\x09c=x / 10 % 10;
\x09\x09d=x % 10;
\x09}
\x09printf("The Inverse Number is ");
\x09scanf("%d",a + b * 10 + c * 100 + d * 1000);
}
这有什么错?为什么一直都是“Input Error!

【编程】从键盘输入一个四位正整数.首先分离出该正整数中的每一位数字,并按逆序显示输出各位数字#include #include void main (){\x09int a,b,c,d,x;\x09printf("请输入一个四位正整数:");\x09scanf("&d",x);\
两个地方错了.
第一,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);