输入成绩输出对应等级的c语言程序
时间: 2023-04-08 15:04:57 浏览: 152
以下是一个简单的C语言程序,可以根据输入的成绩输出对应的等级:
```
#include <stdio.h>
int main() {
float score;
printf("请输入成绩:");
scanf("%f", &score);
if (score >= 90) {
printf("等级为:A\n");
} else if (score >= 80) {
printf("等级为:B\n");
} else if (score >= 70) {
printf("等级为:C\n");
} else if (score >= 60) {
printf("等级为:D\n");
} else {
printf("等级为:E\n");
}
return 0;
}
```
相关问题
用switch语句编写输入学生成绩输出等级c语言
下面是使用switch语句编写输入学生成绩输出等级的C语言代码:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入学生成绩:");
scanf("%d", &score);
switch(score / 10) {
case 10:
case 9:
printf("成绩等级为:优秀\n");
break;
case 8:
printf("成绩等级为:良好\n");
break;
case 7:
printf("成绩等级为:中等\n");
break;
case 6:
printf("成绩等级为:及格\n");
break;
default:
printf("成绩等级为:不及格\n");
break;
}
return 0;
}
```
以上代码中,我们首先定义了一个整型变量score来存储输入的学生成绩。然后使用printf函数输出提示信息,使用scanf函数获取用户输入的学生成绩。基于用户输入的成绩,我们使用score / 10来作为switch语句的判断条件,进而输出对应的等级。
其中,case 10和case 9表示成绩在90-100之间,输出"优秀";case 8表示成绩在80-89之间,输出"良好";case 7表示成绩在70-79之间,输出"中等";case 6表示成绩在60-69之间,输出"及格";default表示成绩低于60,输出"不及格"。
最后,我们使用return 0来结束程序的执行。
以上就是用switch语句编写输入学生成绩输出等级的C语言代码。
用C语言输入学生成绩输出等级
可以使用C语言编写程序来输入学生成绩并输出对应的等级。一种常见的方法是使用switch语句,将学生成绩转化为0~10的整数,然后根据整数值输出对应的等级。下面是一个示例代码:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入学生成绩(0-100):");
scanf("%d", &score);
int grade = score / 10;
switch (grade) {
case 10:
case 9:
printf("成绩等级为A\n");
break;
case 8:
printf("成绩等级为B\n");
break;
case 7:
printf("成绩等级为C\n");
break;
case 6:
printf("成绩等级为D\n");
break;
default:
printf("成绩等级为E\n");
break;
}
return 0;
}
```
该程序首先提示用户输入学生成绩,然后使用scanf函数读取输入的整数值。接着将学生成绩转化为0~10的整数,使用switch语句输出对应的等级。注意,case 10: case 9: 表示当grade的值为10或9时,执行相同的语句。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)