本教程操作环境:windows7系统、c99版本、dell g3电脑。
分析:我们既可以使用else if来进行判断也可以使用switch case来进行判断。
题目要求如下:输入学生成绩,自动判断等级
成绩等级
90<=score<=100 a等级
80<=score<90 b等级
70<=score<80 c等级
60<=score<70 d等级
0
使用else if语句
1、使用switch…case语句判断等级
#include <stdio.h>int main(){ int i; scanf("%d",&i); i/=10; switch(i){ case 9: printf("a"); break; case 8: printf("b"); break; case 7: printf("c"); break; case 6: printf("d"); break; default: printf("e"); break; } return 0; }
运行结果
2、使用if..else..if语句
#include <stdio.h>int main(){ int score; scanf("%d",&score); if(score>=90)printf("a"); else if(score>=80)printf("b"); else if(score>=70)printf("c"); else if(score>=60)printf("d"); else printf("e"); return 0; }
运行结果
相关推荐:《c语言视频教程》
以上就是c语言输入成绩怎么判断等级的详细内容。
