我以前编的,10个人,5个成绩,改一下就行了
#include<stdio.h>
struct student
{int yuwen;
int shuxue;
int yingyu;
int wuli;
int huaxue;
/*int score[5];*/
}stu[10]={{87,87,56,85,95},{86,78,57,95,77},{76,96,99,75,86},{56,65,76,78,96},{76,64,92,83,54},{75,67,81,92,90},{57,68,60,79,77},{57,76,58,98,68},{57,84,92,97,76},{96,78,79,79,58}};
void f1()
{int i,/*sum[5]={0},j;*/sum=0,sum1=0,sum2=0,sum3=0,sum4=0;
for(i=0;i<10;i++)
/*for(j=0;j<5;j++) */
{ /*sum[j]=sum[j]+stu[i].score[j]; */
sum=sum+stu[i].yuwen;
sum1=sum1+stu[i].shuxue;
sum2=sum2+stu[i].yingyu;
sum3=sum3+stu[i].wuli;
sum4=sum4+stu[i].huaxue;
}
printf("ave yuwen is%d\nave shuxue is%d\nave yingyu is %d\nave wuli is %d \nave huaxue is%d",sum/10,sum1/10,sum2/10,sum3/10,sum4/10);
}
void f2()
{int i,t;
for(i=0;i<5;i++)
{t=(stu[i].yuwen+stu[i].shuxue+stu[i].yingyu+stu[i].wuli+stu[i].huaxue);
printf("\nave stu%d=%d",i+1,t/5);
}
}
main()
{clrscr();
f1();
f2();
}
[此贴子已经被作者于2007-4-25 18:44:43编辑过]