04周-第4-5章-顺序结构与选择结构.ppt

形式2:if-else语句 求两数最大最小值 int x, y, max, min; if (x y) { max = x; min = y; } else { max=y; min=x; } * 多条语句时{}千万不能省略 if (x y) max = x; min = y; else max=y; min=x; 形式2:if-else语句 求两数最大最小值 int x, y, max, min; if (x y){ max = x; min = y; }else{ max=y; min=x; } * int a,b,c, m; // 求a,b,c中最大值,存在m中 if (ab){ if (a c) m = a; else m = c; }else{ if (b c) m = b; else m = c; } if (ab) if (a c) m = a; else m = c; else if (b c) m = b; else m = c; 形式3:if嵌套 * else与if的配对规则: 与上面的、 离它最近的、 且在同一复合语句中 还没有配对的if子语配对。 if-else 配对 if (ab) { if (ac) if

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档