写了个习题,输出有问题,大家帮忙看看错在哪了
程序代码:
#include <stdio.h> #include <stdlib.h> void main(void) { float a[100],sum = 0.0,average; int i = 0,j = 0,c = 0; printf("输入成绩: "); scanf("%f",a); while(a[i] != '\0') { sum = sum + a[i]; i++; } average = sum/i; for(j = 0;j < i; j++) { if(a[j] < average) { c++; } } printf("平均值为%12.2f,低于平均的人数为%d\n",average,c); } vc6 运行的结果: 输入学生成绩: 20 30 40 平均成绩为-101238528.00,低于平均的人数为99 Press any key to continue