帮我编写一个C语言的程序

[复制链接]
查看11 | 回复1 | 2010-5-4 17:17:18 | 显示全部楼层 |阅读模式
我将平均值存在学生信息后面的 #include#include struct student{ char name[10]; char number[10]; float English_Score;
float Math_Score; float C_Score; float Sport_Score; float Average;}stu[10];int main(){ int i; FILE *fp;
for(i=0;i<10;i++) { //输入数据 scanf("%s%s%f%f%f%f",stu.name,stu.number,&stu.English_Score,
&stu.Math_Score,&stu.C_Score,&stu.Sport_Score);
//求平均值 stu.Average=(stu.English_Score+stu.Math_Score+
stu.C_Score+stu.Sport_Score)/4;} printf("\n"); //输出数据
for(i=0;i<10;i++) {
printf("%-8s%-10s%-5.1f%-5.1f%-5.1f%-5.1f%-5.1f\n",stu.name,
stu.number,stu.English_Score,stu.Math_Score,
stu.C_Score,stu.Sport_Score,stu.Average); }
//写入文件
if((fp=fopen("xinxi","w"))==NULL) {
printf("cannot open file!\n");
exit(0); }
for(i=0;i<10;i++) {
fwrite(&stu,sizeof(struct student),1,fp); }
getchar();getchar(); fclose(fp);
return 0;}//另附读入数据模块(要把上个程序得到的xinxi文件拷到当前工作区下) if((fp=fopen("xinxi","r"))==NULL) { printf("cannot open file!\n");exit(0); }
for(i=0;i<10;i++) {fread(&stu,sizeof(struct student),1,fp); }
回复

使用道具 举报

千问 | 2010-5-4 17:17:18 | 显示全部楼层
去里面看看有一个和你差不多的程序,你在改改参考资料:http://songdingchuan.blog.163.com/

已赞过已踩过<
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行