用c语言实现,输入分数,根据分数输出A,B,C,D等级,其中A等级100~85,B等级85~70,C等级70~60,D等级60以下
时间: 2023-10-04 10:05:03 浏览: 141
```c
#include <stdio.h>
int main() {
int score;
printf("请输入分数:");
scanf("%d", &score);
if (score >= 85 && score <= 100) {
printf("A\n");
} else if (score >= 70 && score < 85) {
printf("B\n");
} else if (score >= 60 && score < 70) {
printf("C\n");
} else {
printf("D\n");
}
return 0;
}
```
相关问题
用c语言,且运用switch语句实现,输入分数,根据分数输出A,B,C,D等级,其中A等级100~85,B等级85~70,C等级70~60,D等级60以下
```c
#include <stdio.h>
int main() {
int score;
printf("请输入分数:");
scanf("%d", &score);
switch (score / 10) {
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;
}
```
用C语言要求用户输入一个分数,根据输入的分数输出对应的等级 A 90~100 B 80~89 C 70~79 D 60~69 E 0~59
好的,你的问题很简单。以下是 C 语言的代码:
```c
#include <stdio.h>
int main()
{
int score;
printf("请输入您的分数:\n");
scanf("%d", &score);
if (score >= 90 && score <= 100)
{
printf("恭喜您,您的等级为 A!\n");
}
else if (score >= 80 && score <= 89)
{
printf("您的等级为 B。\n");
}
else if (score >= 70 && score <= 79)
{
printf("您的等级为 C。\n");
}
else if (score >= 60 && score <= 69)
{
printf("您的等级为 D。\n");
}
else if (score >= 0 && score <= 59)
{
printf("您的等级为 E。\n");
}
else
{
printf("输入有误,请输入0-100之间的整数分数。\n");
}
return 0;
}
```
你可以将这段代码保存在一个文件中,例如 `grade.c`, 然后使用 C 编译器进行编译和运行,例如:
```shell
gcc grade.c -o grade
./grade
```
然后按照提示输入分数即可看到对应的等级。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)