scanf函数输入一个百分制成绩,输出成绩等级A、B、C、D、E,其中90~100分为A,80~89分为B,70~79分为C

2024-11-30 17:46:21
推荐回答(2个)
回答1:

楼主请看:
#include
int main()
{ float score;
char grade;
printf("请输入学生成绩:");
scanf("%f",&score);
while (score>100||score<0)
{printf("\n 输入有误,请重输");
scanf("%f",&score);
}
switch((int)(score/10))
{case 10:
case 9: grade='A';break;
case 8: grade='B';break;
case 7: grade='C';break;
case 6: grade='D';break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: grade='E';
}
printf("成绩是 %5.1f,相应的等级是%c\n ",score,grade);
return 0;
}

回答2:

一楼写的很不错,你可以参考一下