输入一批学生的成绩,遇0或负数则输入结束,

题目描述
编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
样例输入
88 71 68 70 59 81 91 42 66 77 83 0
样例输出

=85:2
60-84:7
<60:2


```c
#include<stdio.h>
int main()
{
    int a=0, b=0, c=0;
    int score[20];
    for(int i=0;i<20;i++)
    {
        scanf("%d",&score[i]);
     if(score[i]>=85)
        a++;
        else if(score[i]<60&&score[i]>0)
        c++;
        else if(score[i]>=60&&score[i]<85)
        b++;
    }
    printf(">=85:%d\n60-84:%d\n<60:%d\n",a,b,c);
    return 0;
}


 
哪里错了吗结果出不来

不能在这里return 0,return 0 表示这个程序运行结束了,应该用break。

img

如果有用,请采纳。

没毛病啊

img

在scanf后面加一句判断

scanf("%d",&score[i]);
        if(score[i]==0||score[i]==-1)
            break;

添加判断if(score[i]<=0) return 0;

第三个循环可以直接else,然后b++