利用结构体,完成对三位学生的成绩分析
有一个班的5个学生,有3门课程。
1、求第一门课的平均分;
2、找出有两门以上课程不及格的学生,输出他们的学号和全部课程成绩及平均分
3、找出平均分在90分以上或全部课程成绩在85分以上的学生。
#include<stdio.h>
struct information
{
char name[32];
int no;
int s1;
int s2;
int s3;
};
int Average(struct information *ps)
{
double avg;
avg=((ps[0].s1)+(ps[1].s1)+(ps[2].s1))/3;
printf("avg=%lf\n" , avg);
return 0;
}
int AverageStudent(struct information *ps , int *pavg)
{
int i=0;
for(i=0;i<3;i++)
{
pavg[i]=(ps[i].s1+ps[i].s2+ps[i].s3)/3;
}
return 0;
}
int Warning(struct information *ps,int *pavg)
{
int i=0;
for(i=0;i<3;i++)
{
if( ( (ps[i].s1<60) && (ps[i].s2<60) ) || ( (ps[i].s1<60)&&(ps[i].s3<60)) || ( (ps[i].s3<60) && (ps[i].s2<60) ))
{
printf("Warning!!!Name:%s No:%d 1score:%d 2score:%d 3score:%d avg:%d" ,ps[i].name , ps[i].no,ps[i].s1,ps[i].s2,ps[i].s3,pavg[i]);
}
}
return 0;
}
int Great(struct information *ps ,int *pa)
{
int i=0;
for(i=0;i<3;i++)
{
if( (pa[i]>90) || ( (ps[i].s1>85)&&(ps[i].s2>85)&&(ps[3].s3>85) ) )
{
printf("\nGreat student Name:%s",ps[i].name );
}
}
return 0;
}
int main()
{
int Avg[3]={0};
struct information s[3]={
{"st",11111,55,59,58},{"aa",22222,96,99,54},{"bb",33333,92,95,96}};
Average(s);
AverageStudent(s,Avg);
Warning(s,Avg);
Great(s,Avg);
return 0;
}
分别编写三个函数来实现以上三个要求 struct student { char name[32]; int no; int score[3]; };