编写一个程序,将给定的百分制成绩转换为成绩等级A、B、C、D、E。90分以上为A,80–89分为B,70–79分为C,60–69分为D,60分以下为E
#include <stdio.h>
int main(){
int n;
printf("分数:");
scanf("%d", &n);
if(n < 0 || n >100){ //健壮性
printf("成绩无效!\n");
return 0;
}
switch(n/10){
case 0 : case 1 : case 2 : case 3 : case 4 : case 5 :
printf("Your score is E\n");
break;
case 6:
printf("Your score is D\n");
break;
case 7:
printf("Your score is C\n");
break;
case 8:
printf("Your score is B\n");
break;
default:
printf("Your score is A\n");
break;
}
return 0;
}