具体方法与演示结果如图:
#include "stdio.h"
void main()
{
int i,score;
char band;
for(i=0;i<5;i++)
{
printf("Input Score:");
scanf("%d",&score);
switch(score/10)
{
case 10:
case 9: band='A'; break;
case 8: band='B'; break;
case 7: band='C'; break;
case 6: band='D'; break;
default: band='E'; break;
}
printf("%d的等级为%c\n",score,band);
}
}
Scanner sc = new Scanner(System.in);
System.out.print("请输入成绩:");
int score = sc.nextInt();
System.out.println();
String print;
switch (score/10) {
case 9:
print = "A";
break;
case 8:
print = "B";
break;
case 7:
print = "C";
break;
case 6:
print = "D";
break;
default:
print = "F";
break;
}
System.out.println(score+"等级为"+print);