请大家指点
#include "stdio.h"
struct student{
int num;
char name[15];
int score1;
int score2;
int score3;
int total;
float average;
}stu[10];
int k=0;
/*这是一个全局变量*/
total(struct student *q)
{
int m;
m=q->score1+q->score2+q->score3;
if(k<m)
k=m;
return m;
}
average(struct student *p)
{
float n;
n=(float)((p->score1+p->score2+p->score3)/3);
return n;
}
void main()
{
int i,aver=0,s1=0,s2=0,s3=0;
printf("num\tname\tscore1\t
score2\tscore3\n");
for(i=0;i<10;i++)
{
printf("please input the %d student data:\n",i+1);
scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3);
stu[i].total=total(&stu[i]);
stu[i].average=average(&stu[i]);
}
for(i=0;i<10;i++)
{
s1=s1+stu[i].score1;
s2=s2+stu[i].score2;
s3=s3+stu[i].score3;
aver+=stu[i].average;
if(k==stu[i].total)
k=i;
}
s1=s1/10;
s2=s2/10;
s3=s3/10;
aver=aver/10;
printf("NO\tname\tscore1\tscore2\tscore3\ttotal\taverage\n");
for(i=0;i<10;i++)
printf("%d\t%s\t%d\t%d\t%d\t%d\t%4.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total,stu[i].average);
printf("the score1 average %d \n",s1);
printf("the score2 average %d\n",s2);
printf("the score3 average %d\n",s3);
printf("zong ping jun fen shi %d\n",aver);
printf("xia miao shi zhui gao fen xue sheng de shu ju:\n");
printf("%d\t%s\t%d\t%d\t%d\t%d\t%4.2f",stu[k].num,stu[k].name,stu[k].score1,stu[k].score2,stu[k].score3,stu[k].total,stu[k].average);
}
大家好,我也是初学者,上面是我花了一个多小时才写好的程序,.
我也看出了程序的粗糙,一.没有闪光点,代码质量平平.二.可读性有待加强.请大家指点