c语言,求平均成绩。

#include "stdafx.h"
#include <stdio.h>

struct student
{
int num;
int score;
};
int main()
{
int i,j,c=0,n=0;
float ave;
struct student st[30];
printf("学号 成绩\n");
for(i=0;i<30;i++)
{
scanf("%d%d",&st[i].num,&st[i].score);
if(st[i].num<0||st[i].score<0)
break;
ave+=st[i].score;
n++;
}
ave=ave/n;
printf("%.1f\n",ave);
return 0;
}

就是这么个情况,本来题目还有很多的,可是到这里那个平均成绩总是算不出来,哪里错了啊?

float ave=0.0;
//这里需要赋初值,否则结果不可靠。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-29
float ave;
没有赋初值!!!
改成float ave = 0.0;
第2个回答  2011-06-29
应该是ave未初始化~~可以尝试用debug调试看看