求大神帮忙解决第一题编程?
#include<stdio.h>
#define N 5
struct mstudent { int number; char name[20]; float score[3],average; } stu[N];
void main()
{ FILE *fp;
int i,j;
printf("请输入:学号 姓名 语文成绩 数学成绩 英文成绩(提示:以空格分隔)\n");
for ( i=0;i<N;i++ )
{ printf("(%d) ",i+1);
scanf("%d %s %f %f %f",
&stu[i].number,stu[i].name,
&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].average=0; for ( j=0;j<3;j++ ) stu[i].average+=stu[i].score[j];
stu[i].average/=3;
}
if ( fp=fopen("stud","wb+") )
{
fwrite(stu,sizeof(struct mstudent),N,fp); fclose(fp);
} else printf("无法建立文件。\n");
/*文件内容读取测试
for ( i=0;i<N;i++ ) stu[i].number=0;
if ( fp=fopen("stud","rb") )
{ fread(stu,sizeof(struct mstudent),N,fp); fclose(fp);
fclose(fp);
}
for ( i=0;i<N;i++ )
printf("%8d %20s %5.1f %5.1f %5.1f %5.1f\n",
stu[i].number,stu[i].name,
stu[i].score[0],stu[i].score[1],stu[i].score[2],
stu[i].average);
*/
}
以下是将程序中注释部分去掉后的运行结果
2022-12-05 广告