【发布时间】:2014-10-08 00:01:47
【问题描述】:
这是我的代码,用于使用 for 循环显示数组的总和和平均值,但是当我运行它时,它只为总和和平均值输出 0。
#include <stdio.h>
int main (void){
float grades[12] = {85.0, 77.0, 15.0, 100.0, 90.0, 98.0, 62.0, 84.0, 86.0, 70.0, 100.0, 99.0};
int counter;
float average;
float sum = 0.0;
for(counter = 0; counter == 12; counter++){
sum = sum + grades[counter];
}
average = sum/12;
printf("The sum of the grades is: %f \n", sum);
printf("The average of the grades are: %f \n", average);
system("pause");
}
【问题讨论】:
标签: c arrays for-loop output average