分析:我们既可以使用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; 
}

运行结果

c语言输入成绩怎么判断等级

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语言输入成绩怎么判断等级

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。