当前位置: 代码迷 >> C语言 >> [求助]不知道这段原代码错在那里了.
  详细解决方案

[求助]不知道这段原代码错在那里了.

热度:144   发布时间:2007-10-22 22:58:17.0

scanf的格式很严的
scanf("%d%d\n",&x,&y);
在输入的时候可以是 :5 4(中间是空格)
但是中间决不能有逗号,输入5,4是不对的


----------------解决方案--------------------------------------------------------

如图~这样输入的结果就的不到想要的结果



----------------解决方案--------------------------------------------------------
#include "stdio.h"
#define L(a,b) a%b
int main()
{
int x,y,t;
printf("Please input the two numbers:\n",x,y);
scanf("%d%d\n",&x,&y);
t=L(x,y);
printf("%d\n",t);
return;
}
为什么我这样就运行不了???
修改成这样才行
#include "stdio.h"
#define L(a,b) a%b
int main()
{
int x,y,t;
printf("Please input the two numbers:\n",x,y);
scanf("%d%d",&x,&y);
t=L(x,y);
printf("%d\n",t);
return;
}
麻烦问下...

----------------解决方案--------------------------------------------------------

LZ的错误在此:
看红色的部分:
#include "stdio.h"
#define L(a,b) a%b
void main()
{
int x,y,t;
printf("Please input the two numbers:\n",x,y);
scanf("%d%d\n",&x,&y);
t=L(x,y);
printf("%d\n",t);
}
你看scanf有你那样的输入吗?


----------------解决方案--------------------------------------------------------
scanf里面加\n是什么意思啊
加%d 计算机知道,
加\n就没什么意思了

----------------解决方案--------------------------------------------------------
哦.....明白了
我还是继续看我的基础教程去了....
----------------解决方案--------------------------------------------------------
printf("Please input the two numbers:\n",x,y);

我的印象中原样输出没有红色的那部分吧?

printf("Please input the two numbers: %d,%d\n",x,y);

这样我可以理解。
----------------解决方案--------------------------------------------------------

去掉你在printf("%d%d\n",&x,&y);中的\n就可以了


----------------解决方案--------------------------------------------------------
输入时别加逗号
----------------解决方案--------------------------------------------------------
#include "stdio.h"
#define L(a,b) a%b /*宏本身没问题,问题在下面*/
main()
{
int x,y,t; /*类型是否正确*/
printf("Please input the two numbers:\n",x,y);
scanf("%d%d\n",&x,&y);/scanf()写法是否合乎标准*/
t=L(x,y);
printf("%d\n",t); /*getch()缺少*/
}

----------------解决方案--------------------------------------------------------
  相关解决方案