将以下改为while循环 int i, j, total, t[6]; for (j=0; j<m; j++) { printf("For course %d:\n", j+1); memset(t, 0, sizeof(t)); /* 将数组t的全部元素初始化为0 */ for (i=0; i<n; i++) { if (stu[i].score[j]>=0 && stu[i].score[j]<60) t[0]++; else if (stu[i].score[j]<70) t[1]++; else if (stu[i].score[j]<80) t[2]++; else if (stu[i].score[j]<90) t[3]++; else if (stu[i].score[j]<100) t[4]++; else if (stu[i].score[j] == 100) t[5]++; } for (total=0, i=0; i<=5; i++) { total = total + t[i]; } for (i=0; i<=5; i++) { if (i==0) printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100); else if (i==5) printf("%d\t%d\t%.2f%%\n", (i+5)*10,t[i],(float)t[i]/n*100); else printf("%d-%d\t%d\t%.2f%%\n", (i+5)*10, (i+5)*10+9, t[i], (float)t[i]/n*100); } }
时间: 2024-01-20 20:02:10 浏览: 24
int i, j, total, t[6];
j = 0;
while(j < m) {
printf("For course %d:\n", j+1);
memset(t, 0, sizeof(t)); /* 将数组t的全部元素初始化为0 */
i = 0;
while(i < n) {
if (stu[i].score[j]>=0 && stu[i].score[j]<60) t[0]++;
else if (stu[i].score[j]<70) t[1]++;
else if (stu[i].score[j]<80) t[2]++;
else if (stu[i].score[j]<90) t[3]++;
else if (stu[i].score[j]<100) t[4]++;
else if (stu[i].score[j] == 100) t[5]++;
i++;
}
total = 0;
i = 0;
while(i <= 5) {
total = total + t[i];
i++;
}
i = 0;
while(i <= 5) {
if (i==0) printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100);
else if (i==5) printf("%d\t%d\t%.2f%%\n",(i+5)*10,t[i],(float)t[i]/n*100);
else printf("%d-%d\t%d\t%.2f%%\n",(i+5)*10, (i+5)*10+9, t[i], (float)t[i]/n*100);
i++;
}
j++;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)