#include<stdio.h>
#define n 5
struct student
{int num;
char name[23];
float score[3];
int aver;};
int main()
{
void print2(struct student stu);
void print1(struct student stu);
struct student max(struct student stu[]);
struct student min(struct student stu[]);
struct student stu[n],*p=stu;
int i;
printf("请输入数据:以学号为0结束输入:n");
for(i=0;i<n;i++)
{
scanf("%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
if (stu[i].num==0)
{
break;
}
}
for(i=0;i<n;i++)
{
printf("%dt%st%ft%ft%ft%fn",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].aver);
}
print1(max(p));
print2(min(p));
}
struct student max(struct student stu[])
{int i,m=0;
for(i=0;i<n;i++)
if (stu[i].aver>stu[m].aver) m=i;
return stu[m];
}
struct student min(struct student stu[])
{int i,m=0;
for(i=0;i<n;i++)
if (stu[i].aver<stu[m].aver) m=i;
return stu[m];
}
void print1(struct student stud)
{ printf("n成绩最高的学生是:n");
printf("学号:%dn姓名:%sn三门课成绩:%5.1f,%5.1f,%5.1fn平均成绩:%6.2fn", stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
}
void print2(struct student stud)
{ printf("n成绩最低的学生是:n");
printf("学号:%dn姓名:%sn三门课成绩:%5.1f,%5.1f,%5.1fn平均成绩:%6.2fn",stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
}
很笨拙的程序 不崩溃了 但输出是乱码。。。