正在加载图片...
第5章第4节 解决办法:语句后面加 break语句 switch(表达式) {case常量表达式1:语句1; break; case常量表达式2:语句2; break; case常量表达式n:语句n; break; default:语句n+1 例:输入一个考试分数,输出成绩等级(优、良、中等、及格、不及格) 解法一:用 ifa. else if语句实现 main float score prin(“输入分数”); scanf(“%r”,& rscore); if( score>=90.0) printf(“成绩为:优n”); else if( score>=80.0) printf(“成绩为:良好\n) else if( score>=70.0) printf(“成绩为:中等n”) else if( score>=60.0) printf(“成绩为:及格Ⅶn”); else printf(“成绩为:不及格Ⅷ”);解决办法:语句i后面加break语句 第5章 第4节 switch(表达式) {case 常量表达式1:语句1;break; case 常量表达式2:语句2;break; ..... case 常量表达式n:语句n;break; default : 语句n+1 } 例: 输入一个考试分数,输出成绩等级(优、良、中等、及格、不及格) 解法一:用if... else if 语句实现 main() {float score; printf(“输入分数:”); scanf(“%f”,&score); if (score>=90.0) printf(“成绩为:优\n”); else if (score>=80.0) printf(“成绩为:良好\n”); else if (score>=70.0) printf(“成绩为:中等\n”); else if (score>=60.0) printf(“成绩为:及格\n”); else printf(“成绩为:不及格\n”); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有