|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 1613551 于 2023-2-11 11:51 编辑
我想问一下这串代码存不存在嵌套,为什么答案说不存在嵌套,不是有两个if语句吗?
- #include <stdio.h>
- #include <math.h>
- #include <stdio.h>
- int main()
- {
- int s=2,t=1,a=2,b=4;
- if(a>0)s=s+1;
- if(a>b)t=s+t;
- else if(a=b)t=5;
- else t=2*s;
- printf("s=%d,t=%d",s,t);
- system("pause");
- return 0;
- }
复制代码
因为前面那个 if 在分号那里就结束了,所以这是两个独立的 if
#include <stdio.h>
#include <math.h>
#include <stdio.h>
int main()
{
int s=2,t=1,a=2,b=4;
if(a>0)s=s+1;
if(a>b)t=s+t;
else if(a=b)t=5;
else t=2*s;
printf("s=%d,t=%d",s,t);
system("pause");
return 0;
}
嵌套是这样的:
#include <stdio.h>
#include <math.h>
#include <stdio.h>
int main()
{
int s=2,t=1,a=2,b=4;
if(a>0){ s=s+1;
if(a>b)t=s+t;
else if(a=b)t=5;
else t=2*s; }
printf("s=%d,t=%d",s,t);
system("pause");
return 0;
}
|
|