通过键盘输入,输出成绩等级用C语言
时间: 2024-03-15 13:47:03 浏览: 22
可以按照以下代码实现成绩等级的输出:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score);
if (score >= 90 && score <= 100) {
printf("成绩等级为:A\n");
} else if (score >= 80 && score < 90) {
printf("成绩等级为:B\n");
} else if (score >= 70 && score < 80) {
printf("成绩等级为:C\n");
} else if (score >= 60 && score < 70) {
printf("成绩等级为:D\n");
} else if (score >= 0 && score < 60) {
printf("成绩等级为:E\n");
} else {
printf("输入的成绩不合法!\n");
}
return 0;
}
```
解释一下代码的过程:首先通过 `scanf` 函数从键盘输入一个整数类型的成绩,然后根据成绩的范围判断输出成绩等级。如果成绩不在合法的范围内,则输出一条错误提示。
相关问题
通过键盘输入一个成绩判断他的等级用C语言来完成
好的,我来为您提供一个简单的实现。
```
#include <stdio.h>
int main() {
int score;
printf("请输入您的成绩:");
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;
}
```
以上代码会要求用户输入一个成绩,然后根据分数判断等级,并输出等级信息。如果分数大于等于 90 分,则输出 A 等级;如果分数在 80~89 分之间,则输出 B 等级,以此类推。如果分数不足 60 分,则输出 E 等级。
从键盘输入学生成绩score,按五级制输出优、良、中、及格、不及格。用c语言实现
以下是一个简单的 C 语言程序,可以根据输入的成绩打印出相应的等级:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score);
if (score >= 90) {
printf("优\n");
} else if (score >= 80) {
printf("良\n");
} else if (score >= 70) {
printf("中\n");
} else if (score >= 60) {
printf("及格\n");
} else {
printf("不及格\n");
}
return 0;
}
```
在上面的程序中,我们首先使用 `scanf()` 函数从标准输入中读取一个整数类型的成绩,并将其存储在变量 `score` 中。然后使用一系列的 `if...else` 语句来判断该成绩对应的等级,并打印出相应的结果。最后,程序返回 0,表示正常结束。
相关推荐
![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)