此题为if...else...语句的嵌套,第二if...else...作为第一个if...else...语句else部分的复合语句。
若表达式c>d成立,则执行c=5.0;
否则(表达式c>d不成立)
若表达式c==d成立,则执行c=6.0;
否则,执行c=7.0;
输出c中的值
3.0小于
4.0,因此表达式c>d不成立,执行第二个if…else…。
3.0不等于
4.0,因此表达式c==d不成立,执行c=7.0,将7.0赋给c, 覆盖掉c中的3.0,此时c中的值为7.0
输出此时的c中的值
6.
#include
main()
{ int m;
scanf("%d", &m);
if (m >= 0)
{ if (m%2 == 0) printf("%d is a positive even\n", m);
else printf("%d is a positive odd\n", m); }
else
{ if (m % 2 == 0)printf("%d is a negative even\n", m);
else printf("%d is a negative odd\n", m); }
}
若键入-9,则运行结果为: -9 is a negative odd
7.
#include
main()
{ int num=0;