用c将学生成绩由百分制换算成五分制: A:100-90; B: 89-80; C: 79-70; D: 69-60; E: 59-0 要求:从键盘输入一个百分制成绩,输出对应的五分制等级。
时间: 2023-05-25 11:06:17 浏览: 182
代码如下:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score); // 从键盘输入成绩
printf("对应的五分制等级是:");
if (score >= 90 && score <= 100) {
printf("A");
} else if (score >= 80 && score <= 89) {
printf("B");
} else if (score >= 70 && score <= 79) {
printf("C");
} else if (score >= 60 && score <= 69) {
printf("D");
} else {
printf("E");
}
return 0;
}
```
运行效果如下:
```
请输入成绩:73
对应的五分制等级是:C
```
相关问题
根据百分制成绩输出对应等级。 将某班学生成绩换算成等级,成绩从键盘输入(要求对每个分数段的成绩进行实验并截图保留等级划分结果),对应关系如下, [90,100]→A等级[80,89)→B等级[70,79)→C等级.[60,69)→D等级[0.59)→E等级
要根据百分制成绩输出对应等级,你可以编写一个简单的程序,使用条件语句(if-else)来进行判断。以下是一个示例C程序:
```c
#include <stdio.h>
int main() {
float score;
printf("请输入学生的成绩(范围:0-100):");
// 读取输入的分数
scanf("%f", &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("输入错误,请确保成绩在0到100之间\n");
}
return 0;
}
```
在这个程序中,我们首先提示用户输入成绩,然后根据用户输入的分数值检查所属的等级区间,并相应地打印出等级。
如果你想进行实际的实验并截图,你需要在终端环境下运行这个程序,然后用屏幕截屏工具捕捉当前显示的结果。另外,如果你是在某种开发环境如Visual Studio Code或PyCharm等,可能需要额外设置才能截图。如果想在Windows上截图,可以试试使用`PrintWindow` API;在Linux下,通常使用`xwininfo`命令配合图像抓取工具。
将百分制换算成等级分的程序。等级分为4等,即A、B.c. D, 分別对应分数段为 90~100、 80~89、 60~79、0~59,要求从键盘 录入数据,转换成等级,直到按键“q” 退出。
您好,以下是将百分制换算成等级分的程序:
#include <stdio.h>
int main() {
float score;
char grade;
while (1) {
printf("请输入分数(按q退出):");
if (scanf("%f", &score) != 1) {
break;
}
if (score >= 90 && score <= 100) {
grade = 'A';
} else if (score >= 80 && score <= 89) {
grade = 'B';
} else if (score >= 60 && score <= 79) {
grade = 'C';
} else if (score >= && score <= 59) {
grade = 'D';
} else {
printf("输入的分数不合法,请重新输入!\n");
continue;
}
printf("对应的等级为:%c\n", grade);
}
return ;
}
阅读全文
相关推荐
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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://img-home.csdnimg.cn/images/20241231044833.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)