请问各位高手,此道题中为什么不能求出单科的平均成绩

来源:百度知道 编辑:UC知道 时间:2024/09/23 12:27:37
#include<stdio.h>
struct student
{ char num[10];
char name[8];
int score_ENG,score_CHN,score_math;
double avr;
double avr_ENG;
double avr_CHN;
double avr_math;
}stu[30];
void main()
{ int i,j,t,sum,sum_ENG,sum_CHN,sum_math;
double avr_ENG,avr_CHN,avr_math;
FILE *fp;
sum_ENG=0;
sum_CHN=0;
sum_math=0;
for(i=1;i<=30;i++)
{ printf("\n please input NO. %d score:\n",i);
printf("stuNO:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
printf("score_ENG.");
scanf("%d",&stu[i].score_ENG);
printf("score_CHN.");
scanf("%d",&stu[i].score_CHN);
printf("score_math.");
scanf("%d",&stu[i].score_math);
sum=stu[i].score_ENG+stu[i].score_CHN+stu[i].score_math;
stu[i].avr=sum/3.

请注意倒数几行代码,即:
...
avr_ENG=sum_ENG/30.0;
printf("avr_ENG=%5.1f",stu[i].avr_ENG);

/*把printf("avr_ENG=%5.1f",stu[i].avr_ENG); 换成printf("avr_ENG=%5.1f",avr_ENG);
或者,
还有一个下策,也能输出正确的结果,把avr_ENG=sum_ENG/30.0;改成stu[i].avr_ENG=sum_ENG/30.0;改成*/

avr_CHN=sum_CHN/30.0;
printf("avr_CHN=%5.1f",stu[i].avr_CHN);
avr_math=sum_math/30.0;
printf("avr_math=%5.1f",stu[i].avr_math);
fp=fopen("d:\\阿挺的东西\\stud","w");
for(i=1;i<=30;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

你在声明struct student类型时,有些失误.英语等平均成绩是30个学生共享的,而你把它放在一个学生的记录中!这样很浪费空间
把它们删掉.
struct student
{ char num[10];
char name[8];
int score_ENG,score_CHN,score_math;
double avr;
}stu[30];

请问各位高手,此道题中为什么不能求出单科的平均成绩 我的三星D608为什么在听歌时,不过三首,手机就发热?请问各位高手是何原因,如何解决?小D在此多谢谢!! 请问一下各位高手,为什么装完瑞星杀毒软件后,上铁通的辽东宽带网播放不了影片了,如何解决此问题?? 请问各位高手,我给手机下载的小电影为什么放不出来? 想请问各位高手:为什么有些花只开花不结果? 请问各位高手:在播放视频或电影时画面为什么不连续? 为什么有个文件老删除不掉。请问各位高手这怎么才能删除啊。 请问各位高手,多普达d828+为什么电脑不认它呀? 请问各位大侠,我的木马分析专家会员版不能注册,不知道为什么?请各位高手指点. 各位高手请问symantecAntiVirus此款杀毒软件是否是免费的?