#include <stdio.h>
void main()
{
/*方法一
int score;
printf("请输入分数:\n") ;
scanf("%d",&score);
if (score>=90&&score<100)
{
printf("等级为A\n") ;
}
else if (score>=80)
{
printf("等级为B\n") ;
}
else if (score>=70)
{
printf("等级为C\n") ;
}
else if (score>=60)
{
printf("等级为D\n") ;
}
else
{
printf("等级为E\n") ;
}
*/
//方法二
float score;
printf("请输入学生成绩:\n") ;
scanf("%f",&score);
int s=score/10; // 强制转换
switch (s)
{
case 10:
case 9:
printf("等级为A\n") ;
break ;
case 8:
printf("等级为B\n") ;
break ;
case 7:
printf("等级为C\n") ;
break ;
case 6:
printf("等级为D\n") ;
break ;
default:
printf("等级为E\n") ;
break ;
}
}
原文地址:http://www.cnblogs.com/wenhuan/p/3913291.html