<pre name="code" class="cpp">/*-----------------------------------------------
名称:判断成绩等级
编写:钱钰 51131523
班级:电子科学与工程学院 电子信息工程15班
日期:14.10.21
内容:85-100 A;10-84 B;60-69;C;<60 D;
1.首先多个数据输入,-1退出,分别使用switch和if
------------------------------------------------*/
#include <stdio.h>
int main()
{
int scores,i=1;//i用于记录数据个数
printf("Please enter the scores(-1 to quit):\n#1 : ");
scanf("%d",&scores);
while(scores!=-1)
{
if( scores <= 100 && scores >= 85 )
printf("The Grade is: A\n");
else if ( scores < 85 && scores >= 70 )
printf("The Grade is: B\n");
else if ( scores < 70 && scores >= 60 )
printf("The Grade is: C\n");
else if ( scores <60 && scores >= 0 )
printf("The Grade is: D\n");
switch(scores/5)
{
case 20:
case 19:
case 18:
case 17: printf("The Grade is:A\n");break;
case 16:
case 15:
case 14: printf("The Grade is:B\n");break;
case 13:
case 12: printf("The Grade is:C\n");break;
default: printf("The Grade is:D\n");
}
printf("#%d : ",i+1);//读入下一个成绩
scanf("%d",&scores);
i++;
}
return 0;
}
C语言第三次作业
最新推荐文章于 2021-05-20 04:15:07 发布