c语言if语句使用

#include<stdio.h>
main()
{
int x=1,y=0;
if(!x) y++;
else if(x==0)
if(x) y+=2;
else y+=3;
printf("%d\n",y);
}
运行结果是0,为什么呢?

第1个回答  2014-08-23
main()
{
int a=3,b=4,c=5,t=99;
if(b<a&&a<c)
{t=a;}
a=c;
c=t;
if(a<c&&b<c){ t=b;}
b=a;
a=t;
printf("%d%d%d\n",a,b,c);
}
第一次 表达式为假 执行 a=c,c=t
第二次 表达式为真 执行下面三个语句 然后输出
a=4,b=5,c=99
打字不易,如满意,望采纳。
第2个回答  推荐于2016-06-27

整理一下,即

#include<stdio.h>
main()
{
 int x=1,y=0;
 if(!x) 
 {
     y++;
  }
 else 
 {
     if(x==0)
     {
         if(x) 
         {
             y+=2;
         }
         else 
         {
             y+=3;
         }
     }
 } 
 printf("%d\n",y);  
}

 x值为1,显然y值没有改变

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网