#includevoid main(){int x,y;x=2,y=2;if(x==1)if(x==2)printf("x=%d\n",x=x+y);elseprintf("x=%d\n",x=x-y);printf("x=%d\n",x); }
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 08:51:07
#includevoidmain(){intx,y;x=2,y=2;if(x==1)if(x==2)printf("x=%d\n",x=x+y);elseprintf("x=%d\n",x=x-y);
#includevoid main(){int x,y;x=2,y=2;if(x==1)if(x==2)printf("x=%d\n",x=x+y);elseprintf("x=%d\n",x=x-y);printf("x=%d\n",x); }
#include
void main()
{
int x,y;
x=2,y=2;
if(x==1)
if(x==2)
printf("x=%d\n",x=x+y);
else
printf("x=%d\n",x=x-y);
printf("x=%d\n",x);
}
#includevoid main(){int x,y;x=2,y=2;if(x==1)if(x==2)printf("x=%d\n",x=x+y);elseprintf("x=%d\n",x=x-y);printf("x=%d\n",x); }
因为 else会和离他最近的一个if配对,那么程序就成这样了~!
#include
void main()
{
int x,y;
x=2,y=2;
if(x==1)
{if(x==2)
printf("x=%d\n",x=x+y);
else
printf("x=%d\n",x=x-y);
}
printf("x=%d\n",x);
}
所以是不执行你认为要执行的if(x==2)的
如果想要他执行,可以这样写:
#include
void main()
{
int x,y;
x=2,y=2;
if(x==1);
if(x==2)
printf("x=%d\n",x=x+y);
else
printf("x=%d\n",x=x-y);
printf("x=%d\n",x);
}