本教程操作环境: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<score<60 | E等级 |
C语言中输入成绩后自动判断等级功能的两种实现方式
使用switch...case语句判断等级
使用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语言输入成绩怎么判断等级的详细内容,更多请关注悠悠之家其它相关文章!
发表评论 取消回复