请编写main函数,输入一个百分制成绩score,根据成绩打印5级等级。
时间: 2023-04-01 13:03:13 浏览: 138
好的,我可以回答这个问题。以下是代码:
```
#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 ;
}
```
相关问题
请编写main函数,输入一个百分制成绩score,根据成绩打印5级等级。即(0~59:E:60~65等)使用if语句,根据成绩输出A等B等
以下是由 CSDN 开发的 C 知道的回答:
请看以下代码:
```
#include <stdio.h>
int main() {
int score;
printf("请输入百分制成绩:");
scanf("%d", &score);
if (score >= 90) {
printf("A等\n");
} else if (score >= 80) {
printf("B等\n");
} else if (score >= 70) {
printf("C等\n");
} else if (score >= 60) {
printf("D等\n");
} else {
printf("E等\n");
}
return ;
}
```
以上代码可以根据输入的百分制成绩,输出相应的等级。
题目:请编写main函数,输入一个百分制成绩score,根据成绩打印5级等级。 (即0~59:E;60~69:D;70~79:C;80~89:B; 90~100:A) 要求:使用if语句,根据成绩输出 A等!或 B等!或 C等!或 D等!或 E等!
以下是您所需的main函数的示例代码:
```cpp
#include <iostream>
int main() {
int score;
std::cout << "请输入百分制成绩: ";
std::cin >> score;
if (score >= 90 && score <= 100) {
std::cout << "A等!" << std::endl;
} else if (score >= 80 && score < 90) {
std::cout << "B等!" << std::endl;
} else if (score >= 70 && score < 80) {
std::cout << "C等!" << std::endl;
} else if (score >= 60 && score < 70) {
std::cout << "D等!" << std::endl;
} else if (score >= 0 && score < 60) {
std::cout << "E等!" << std::endl;
} else {
std::cout << "无效的成绩!" << std::endl;
}
return 0;
}
```
您可以将此代码保存为.cpp文件并在编译器中运行。输入一个百分制成绩,程序将根据成绩打印相应的等级。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![java](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)