解题思路:
1. 首先,定义了一个包含100个整数的数组s,以及三个计数器a、b和c,分别用于计算分数大于等于85、在60到84之间以及小于60的分数的数量。
2. 然后,使用do-while循环从用户输入中读取分数,直到输入为0为止。每次读取一个分数,就将其存储在数组s中,并将索引i递增。
3. 接下来,使用while循环遍历数组s中的每个元素(即分数),并根据分数的范围更新计数器a、b和c的值。
4. 最后,打印出三个计数器的值,分别表示分数大于等于85、在60到84之间以及小于60的数量。
注意事项:
i = 0;
不能忘写。
参考代码:
#include <stdio.h> #include <math.h> int main() { int s[100],a = 0,b = 0,c = 0; int i = 0,ss; do{ scanf("%d",&ss); s[i] = ss; i++; }while(ss != 0); i = 0; while(s[i] != 0){ if(s[i] >= 85){ a++; }else if(s[i] >=60 && s[i] <=84){ b++; }else{ c++; } i++; } printf(">=85:%d\n",a); printf("60-84:%d\n",b); printf("<60:%d\n",c); return 0; }
0.0分
0 人评分