当前位置: 代码迷 >> C语言 >> C语言编辑题
  详细解决方案

C语言编辑题

热度:260   发布时间:2007-06-17 18:35:27.0
C语言编辑题
给出一百分制成绩,要求输出成绩等级    ‘A’.‘B’.‘C’.‘D’.‘E’。90分以上为‘A’,80~89分为‘B’,70~79分为‘C’,60~69分为‘D’,60分一下为‘E’ 请大家帮帮忙好吗
搜索更多相关的解决方案: C语言  

----------------解决方案--------------------------------------------------------
回复:(formula)C语言编辑题
请大家帮帮忙啊 谢谢拉
----------------解决方案--------------------------------------------------------

#include<stdio.h>

void main()
{
float x;
printf("Input a score:");
scanf("%f",&x);
if(x>=90)
printf("A\n");
else if(x>=80)
printf("B\n");
else if(x>=70)
printf("C\n");
else if(x>=60)
printf("D\n");
else
printf("E\n");
}


----------------解决方案--------------------------------------------------------
回复:(love154139)#includevoid ...
非常感谢!!!
----------------解决方案--------------------------------------------------------
用switch函数更方便
----------------解决方案--------------------------------------------------------
我觉的题目倒过来倒是可以用switch函数...
----------------解决方案--------------------------------------------------------

楼上既然提到了switch()函数,就用它来实现一下.

#include <stdio.h>
#include <conio.h>
int main(void)
{
int score;
clrscr();
scanf("%d",&score);
switch((int)(score/10))
{
case 0: case 1: case 2: case 3: case 4:
case 5: printf("E\n");break;
case 6: printf("D\n");break;
case 7: printf("C\n");break;
case 8: printf("B\n");break;
case 9:
case 10:printf("A\n");break;
}
getch();
}


----------------解决方案--------------------------------------------------------
还是楼上的好,写出来了,我只说说没写。。。
----------------解决方案--------------------------------------------------------

老潭的C语言中有这原本题目
----------------解决方案--------------------------------------------------------
  相关解决方案