第5題
#include
#include
int main(void)
{
int score[500] = {0}, sum = 0;
int i = 0;
int range[6] = {0,0,0,0,0,0};
for(i = 0;score[i-1] != 999 ; i++)
{
scanf("%d", &score[i]);
while((score[i] < 0) || (score[i] > 100) && (score[i] != 999))
{
if((score[i] < 0) || (score[i] > 100 && (score[i] != 999)))
{
printf("請重新輸入\n");
scanf("%d", &score[i]);
}
}
sum += score[i];
}
sum -= 999;
sum /= (i - 1);
printf("全班國文總平均為%d分\n",sum);
for(i = 0 ;score[i] != 999 ; i++)
{
if(score[i] >= 0 && score[i] <= 59)
range[0]++;
else if(score[i] >= 60 && score[i] <= 69)
range[1]++;
else if(score[i] >= 70 && score[i] <= 79)
range[2]++;
else if(score[i] >= 80 && score[i] <= 89)
range[3]++;
else if(score[i] >= 90 && score[i] <= 99)
range[4]++;
else if(score[i] == 100)
range[5]++;
}
printf(" 0~59分 %d 位學生\n",range[0]);
printf("60~69分 %d 位學生\n",range[1]);
printf("70~79分 %d 位學生\n",range[2]);
printf("80~89分 %d 位學生\n",range[3]);
printf("90~99分 %d 位學生\n",range[4]);
printf(" 100分 %d 位學生\n",range[5]);
system("pause"); return(0);
}
留言
張貼留言