用c语言编程:给出一个百分制的成绩,要求输出成绩等级“A”、“B”,“C”,“D”,“E”。90分以上的为:“A”级,80~89分的为“B”,70~79分的为“C”,60~69分的为“D”,60分以下的为“E”。
时间: 2023-05-14 11:06:20 浏览: 48
可以使用以下代码实现:
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &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;
}
相关问题
用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语言代码,实现输入一个百分制成绩,输出对应的等级。
好的,以下是一段用 C 语言编写的代码,可以实现对输入的百分制成绩进行转换并输出对应的等级:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入百分制成绩:");
scanf("%d", &score);
if(score < 0 || score > 100) {
printf("输入不合法!");
return 0;
}
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;
}
```
这段代码中,我们首先通过 `scanf()` 函数读取用户输入的百分制成绩,然后使用 `if...else` 分支结构对输入的成绩进行判断,并输出对应的成绩等级。请注意,在判断百分制成绩是否合法时,我们使用了 `score < 0 || score > 100` 的条件来进行限制,确保用户输入的成绩在合法范围内。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![sbt](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)