switch case语句例子成绩
时间: 2023-08-28 11:16:25 浏览: 336
switch case语句可以用来根据不同的成绩输出不同的评级。下面是三个例子:
例子1:
```c
#include<stdio.h>
int main() {
int score;
printf("请输入学生成绩: \n");
scanf("%d",&score);
switch(score/10) {
case 10:
printf("考了满分\n");
break;
case 9:
printf("成绩优秀\n");
break;
case 8:
printf("成绩良好\n");
break;
case 7:
printf("成绩中等\n");
break;
case 6:
printf("成绩及格\n");
break;
default:
printf("成绩不及格\n");
break;
}
return 0;
}
```
例子2:
```c
#include<stdio.h>
int main() {
long score;
char mark;
scanf("%ld", &score);
switch (score/10) {
case 10:
case 9:
mark='A';
break;
case 8:
mark='B';
break;
case 7:
mark='C';
break;
case 6:
mark='D';
break;
default:
mark='E';
break;
}
printf("%c\n", mark);
return 0;
}
```
例子3:
```c
#include<stdio.h>
int main() {
int score;
printf("请输入学生成绩: \n");
scanf("%d",&score);
switch(score) {
case 100:
printf("满分\n");
break;
case 90:
printf("优秀\n");
break;
case 80:
case 70:
case 60:
printf("及格\n");
break;
default:
printf("不及格\n");
break;
}
return 0;
}
```
这些例子展示了使用switch case语句根据不同的成绩输出不同的评级。每个例子都包含了不同的判断条件和对应的输出语句。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [c语言switch case语句使用例子](https://blog.csdn.net/weixin_31639069/article/details/117057236)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [C语言——switch case 语句判断学生成绩](https://blog.csdn.net/weixin_42900834/article/details/113338384)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [C语言使用switch语句实现成绩划分](https://blog.csdn.net/m0_73599439/article/details/127437151)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文