c语言题目:给出一百分制成绩,要求输出成绩等级‘A✀、’B‘、✀C✀、‘D✀、✀E’。90分以上为A,80~89分为B,

2024-11-05 03:54:50
推荐回答(5个)
回答1:

#include

int main()

{

int score, m;

scanf("%d", &score);

while (score < 0 || score > 100){

printf("Error! Retry!\n");

scanf("%d", &score);

}

m= score / 10;

if (m>= 9)

printf("Grade is A!\n");

switch(m){

case 0: printf("Grade is E!\n"); break;

case 1: printf("Grade is E!\n"); break;

case 2: printf("Grade is E!\n"); break;

case 3: printf("Grade is E!\n"); break;

case 4: printf("Grade is E!\n"); break;

case 5: printf("Grade is E!\n"); break;

case 6: printf("Grade is D!\n"); break;

case 7: printf("Grade is C!\n"); break;

case 8: printf("Grade is B!\n"); break;

}

return 0;

}

扩展资料

其他实现输出成绩等级‘A'、’B‘、'C'、‘D'、'E’。90分以上为A,80~89分为B,70~79分为C,60~69分为D,60分一下为E的方法:

#include

int main()

{

int score;

scanf("%d", &score);

while (score < 0 || score >100){

printf("Error! Retry!\n");

scanf("%d", &score);

}

if (score < 60)

printf("Grade is E!\n");

else if (score >= 60 && score < 70)

printf("Grade is D!\n");

else if (score >= 70 && score < 80)

printf("Grade is C!\n");

else if (score >=80 && score < 90)

printf("Grade is B!\n");

else

printf("Grade is A!\n");

return 0;

}

回答2:

#include
int 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);
return 0;
}

回答3:

#include
main()
{
int num;
printf("qing shu ru yi ge cheng ji:");
scanf("%d", &num);
if(num>=0&&num<=100) {
switch (num/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;
}}
else
printf("qing shu ru zheng que de fen shu:");
getch();
}

回答4:

switch()语句就可以阿

回答5:

#include
main()
{
int iNum;
sacnf("%d", &iNum);
switch (iNum / 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;
}
}
看的明白吧???