C语言输入学生分数(0-100),输出等级:0~59为E,60~69为D,70~79为C,80~89为B,90~100为A
时间: 2024-06-10 22:07:52 浏览: 15
。好的,这是一个典型的判断语句题目,我们可以使用 if else 语句来完成这个问题。具体的代码如下:
```c
#include <stdio.h>
int main() {
int score;
scanf("%d", &score);
if(score < 60) {
printf("E");
} else if (score < 70) {
printf("D");
} else if (score < 80) {
printf("C");
} else if (score < 90) {
printf("B");
} else {
printf("A");
}
return 0;
}
```
当输入一个学生的分数时,程序会根据分数的大小打印出相应的等级。比如,当输入的分数为 76 时,程序会输出 C。
希望我的回答能够对你有所帮助。如果你还有其他问题,请随时问我哦。
相关问题
输入一个等级,输出对应的分数 A、a:90-100 B、b:80-89 C、c:70-79 D、d:60-69 E、e:0-59 其他:错误用c语言编写程序
以下是使用 C 语言编写的程序,可以实现输入等级,输出对应分数的功能:
```c
#include <stdio.h>
int main() {
char grade;
int score;
printf("请输入等级:");
scanf("%c", &grade);
switch (grade) {
case 'A':
case 'a':
score = 90;
break;
case 'B':
case 'b':
score = 80;
break;
case 'C':
case 'c':
score = 70;
break;
case 'D':
case 'd':
score = 60;
break;
case 'E':
case 'e':
score = 0;
break;
default:
printf("输入错误!\n");
return 0;
}
printf("%c 对应的分数是:%d\n", grade, score);
return 0;
}
```
需要注意的是,此程序仅支持单个字符的输入,如果需要支持字符串输入,则需要使用 `gets` 函数或者其他字符串输入函数。
用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)
![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)