用c语言编写程序,输入一个百分制成绩(整数)按要求输出相应的字符串信息,对应关系为:excellent 90-100,good80-89,middle 70-79,pass60-69,fail60以下或100以上
时间: 2023-05-19 12:07:04 浏览: 64
好的,这是一个简单的程序,以下是代码:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score);
if (score >= 90 && score <= 100) {
printf("excellent\n");
} else if (score >= 80 && score <= 89) {
printf("good\n");
} else if (score >= 70 && score <= 79) {
printf("middle\n");
} else if (score >= 60 && score <= 69) {
printf("pass\n");
} else {
printf("fail\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语言编写一个程序输入一个三位正整数要求反向输出对应的整数如输入123则输出321编写程序
好的,以下是用C语言编写的程序:
```c
#include <stdio.h>
int main() {
int num, digit1, digit2, digit3;
printf("请输入一个三位正整数:");
scanf("%d", &num);
digit1 = num % 10; // 获取个位数字
digit2 = num / 10 % 10; // 获取十位数字
digit3 = num / 100; // 获取百位数字
printf("反向输出的整数为:%d%d%d\n", digit1, digit2, digit3);
return 0;
}
```
程序思路:
1. 定义变量 `num`,用于存储输入的三位正整数;
2. 通过 `scanf` 函数获取用户输入的值,并将其存储到 `num` 变量中;
3. 通过取模运算 `%` 获取 `num` 的个位数字 `digit1`;
4. 通过整除运算 `/` 和取模运算 `%` 获取 `num` 的十位数字 `digit2`;
5. 通过整除运算 `/` 获取 `num` 的百位数字 `digit3`;
6. 通过 `printf` 函数输出 `digit1`、`digit2` 和 `digit3`,并按照指定格式输出。
这样,当用户输入 123 时,程序会输出 321。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![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)