用if-else语句编程根据输入的百分制成绩score,转换成相应的五分制成绩grade后输出。已知转换标准为:
0-59 E
60-69 D
70-79 C
80-89 B
90-100 A
**输入格式要求:"%d" 提示信息:"Please enter score:"
**输出格式要求:"Input error!\n" "%d——A\n"
程序运行示例1如下:
Please enter score:15
15——E
程序运行示例2如下:
Please enter score:85
85——B
#include<stdio.h>
void main()
{printf("Please enter score:");
int x;
scanf("%d",&x);
if(x>=0,x<=59)
printf("%d——E\n",x);
else {if(x>=60,x<=69)
printf("%d——D\n",x);
else {if(x>=70,x<=79)
printf("%d——C\n",x);
else {if(x>=80,x<=89)
printf("%d——B\n",x);
else { if(x<0,x>100)
printf("Input error!\n");
else printf("%d——A\n",x);}}}}
}
或者
#include<stdio.h>
void main()
{printf("Please enter score:");
int x,y;
scanf("%d",&x);
if(x<0||x>100)
printf("Input error!");
else{y=x/10;}
switch(y)
{case 10:
case 9:
printf("%d--A\n",x);
break;
case 8:
printf("%d--B\n",x);
break;
case 7:
printf("%d--C\n",x);
break;
case 6:
printf("%d--D\n",x);
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
printf("%d--E\n",x);
break;
}
}