常用的方法 就是把分数除10
然后对结果进行switch
事先编好程序,要求分别用if语句和switch语句实现。运行程序,并检查结果是否正确。
② 再运行一次程序,输入分数为负值(如-70),这显然是输入时出错,不应给出等级。修改程序,使之能正确处理任何数据:当输入数据大于100或小于0时,通知用户“输入数据错”,程序结束。
90-100:A,80-89:B,。。0-59:E
#include
main(){
int v;
int f;
printf("input fenshu between 0 and 100 :");
scanf("%d",&f);
v = f / 10;
printf("the Mark is: ");
switch(v){
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;
#include "stdio.h"
void main()
{
int fenshu = 0;
while(1)
{
printf("\n\n\n请输入整数(输入65535退出程序):");
scanf("%d",&fenshu);
getchar();
if( fenshu == 65535)
{
printf("程序退出!");
break;
}
if( fenshu > 100 || fenshu < 0 )
{
printf("输出非法,请重新输入!\n");
continue;
}
switch(fenshu/10)
{
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;
}
}
}
假定输入分数为整型,0-100
90-100:A,80-89:B,。。0-59:E
#include
main(){
int v;
int f;
printf("input fenshu between 0 and 100 :");
scanf("%d",&f);
v = f / 10;
printf("the Mark is: ");
switch(v){
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;
}
return 0;
}
常用的方法 就是把分数除10
然后
对结果进行switch
0 ~5
6
7
8
9 ~10
五个段。
int main(){
int score=0;
char op=0;
printf("input the score:");
scanf("%d",&score);
if(score<0 || score>100){
printf("重新输入,score必须为0-100\n");
return -1;
}
if(score==100){
printf("A\n");
return 0;
}
switch(score/10%10){
case 0:
case 1:
case 2:
case 3:
case 4:
case 5: printf("A\n");break;
case 6: printf("B\n");break;
case 7: printf("C\n");break;
case 8: printf("D\n");break;
case 9: printf("E\n");break;
}
return 0;
}