C语言编程:采用switch语句编写成绩等级:100-90分为A,75-89为B,65-74为C,60-64为D,小于60为E
发布网友
发布时间:2022-04-19 10:54
我来回答
共3个回答
热心网友
时间:2023-10-24 05:18
【俊狼猎英】团队为您解答~
只要分好组就好了吧,用除以5得到的商作为变量
int x,score;
x=score/5;
switch(x){
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
printf("F");
break;
以下类推就好了,总共要写21个case
热心网友
时间:2023-10-24 05:18
#include<stdio.h>
main()
{
int x;
char y;
retry:
printf("请输入成绩:\n");
scanf("%d",&x);
if(x<0||x>100)
{printf("成绩输入错误\n");
goto retry;
}
switch(x/5)
{
case 12: y='D';break;
case 13:
case 14: y='C';break;
case 15:
case 16:
case 17: y='B';break;
case 18:
case 19:
case 20: y='A';break;
default :y='E';break;
}
printf("%d分的等级为%c.\n",x,y);
}
//成功运行
热心网友
时间:2023-10-24 05:19
#include <stdio.h>
int main () {
int n;
char c;
scanf("%d",&n);
switch (n / 10) {
case 10: c = 'A'; break;
case 9: c = 'A'; break;
case 8: c = 'B'; break;
case 7: if (n > 74) c = 'B'; else c = 'C'; break;
case 6: if (n > 64) c = 'C'; else c = 'D'; break;
default: c = 'E'; break;
}
printf("%c\n",c);
return 0;
}