输入百分制的学生成绩,输出A(90-100),B(80-89),C(70-79),D(60-69),E(60分以下)等级

2024-11-30 06:38:54
推荐回答(4个)
回答1:

#include

int main()
{
int s;
printf("请输入一个成绩:");
scanf("%d", &s);
if(s>100 || s < 0)
{
printf("输入了一个错误的成绩。\n");
return 1;
}
char ch;
switch(s/10)
{
case 10:
case 9: ch = 'A'; break;
case 8: ch = 'B'; break;
case 7: ch = 'C'; break;
case 6: ch = 'D'; break;
default:
ch = 'E'; break;
}
printf("您输入的成绩等级为:%c\n", ch);
return 0;
}

回答2:

#include
void 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);
}

回答3:

#include
void main(){
int s;
printf("输入成绩:");
scanf("%d",&s);
if(s>100 || s<0)
printf("输入错误!\n");
else if(s>=90)
printf("A\n");
else if(s>=80)
printf("B\n");
else if(s>=70)
printf("C\n");
else if(s>=60)
printf("D\n");
else
printf("E\n");
}

回答4:

#include
int main()
{
int m,n;
scanf("%d",&n);
m=n/10;
switch(m)
{
case 9:printf("A");break;
case 8:printf("B"); break;
case 7:printf("C");break;
case 6:printf("D");break;
default:printf("E");

}

return 0;
}