用c语言 给出一个百分制成绩,要求按如下规则输出成绩等级:90-100分为优秀,80-89分为良好,70-79为中等,60-69分为及格,60分以下为不及格的代码
时间: 2024-03-20 12:39:39 浏览: 48
以下是用 C 语言编写的根据成绩等级输出的代码:
```c
#include <stdio.h>
int main() {
float score;
printf("请输入百分制成绩:");
scanf("%f", &score);
if (score >= 90 && score <= 100) {
printf("成绩等级为:优秀\n");
} else if (score >= 80 && score <= 89) {
printf("成绩等级为:良好\n");
} else if (score >= 70 && score <= 79) {
printf("成绩等级为:中等\n");
} else if (score >= 60 && score <= 69) {
printf("成绩等级为:及格\n");
} else if (score >= 0 && score < 60) {
printf("成绩等级为:不及格\n");
} else {
printf("输入的成绩无效!\n");
}
return 0;
}
```
运行该程序,输入成绩,即可输出对应的成绩等级。
相关问题
用C语言给出一百分制成绩,要求输出成绩等级A,90分以上的为A
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score);
if (score >= 90) {
printf("成绩等级为A\n");
} else {
printf("成绩等级为B及以下\n");
}
return 0;
}
```
注意:这里只是一个简单的示例代码,实际应用中需要考虑更多的情况,比如输入的成绩是否合法等。
C语言成绩90-100分为优秀,70-89分为良好,60-69分为合格,60分以下为不及格。使用switch语句编写程序实现 输入某学生成绩,输出等级。
```
#include <stdio.h>
int main() {
int score;
printf("请输入学生成绩:");
scanf("%d", &score);
switch (score / 10) {
case 10:
case 9:
printf("优秀\n");
break;
case 8:
case 7:
printf("良好\n");
break;
case 6:
printf("合格\n");
break;
default:
printf("不及格\n");
break;
}
return 0;
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)