条码的工作原理:请教C语言if嵌套的一个程序?

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/04 17:07:03
这是一个比较a,b,c三者大小的一个程序,请问程序哪里写错了?
main()
{
int a,b,c;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
printf("c=");
scanf("%d",c);
if(a<b)
if(c<b)
printf("b is max and it is %d\n",a);
else
printf("c is max and it is %d\n",c);
else
if(c<a)
printf("a is max and it is %d\n",b);
else
printf("c is max and it is %d\n",c);
}

main()
{
int a,b,c;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
printf("c=");
scanf("%d",&c);
if(a<b)
{
if(c<b)
printf("b is max and it is %d\n",b);
else
printf("c is max and it is %d\n",c);
}
else
{
if(c<a)
printf("a is max and it is %d\n",a);
else
printf("c is max and it is %d\n",c);
}
}

除了
printf("b is max and it is %d\n",a);//应该是... ,b);
printf("c is max and it is %d\n",c); //应该是... ,c);
的错误之外,我实在看不出有什么错误。
if语句中如果只有一条语句,确实不用花括号的。

程序在if嵌套的用法上没有错误,我用tc2.0测试过可以执行,用visual
c++6.0可以编译,连接,无错,但在执行上却不可执行,需要关闭,不知是为什么。哪位高手也来解答一下啊。

if后用{}表示范围,并且else与最近的if搭配。这种没有{}的if不是好的编程习惯

第一 line 9: scanf("%d",c); c前面没有&
第二 line 17:printf("a is max and it is %d\n",b); 里面应该写a (笔误吧?:-)
第三 main 函数结尾要return 0; MSVC++下导致warning.某些编译 器会报错

if(a<b) 后面没有子语句,也没有加上分号