一个班4个学生,5门课程;

1.求第一门课程的平均分;
2.找出有两门以上课程不及格的学生,输出学号和群不课程成绩及平均成绩;
3.找出平均成绩在90分以上或全部课程成绩在85分以上学生;
【一个班4个学生,5门课程;】#include
int main()
{
void avsco(float *,float *);
void avcour1(char (*)[10],float *);
void fail2(char course[5][10],int num[],float *pscore,float aver[4]);
void good(char course[5][10],int num[4],float *pscore,float aver[4]);
int i,j,num[4],*pnum; //编号码是整型数据;
float score[4][5],*pscore,*paver,aver[4]; //分数都为float类型数据;
char (*pcourse)[10],course[5][10];
printf("please input course:/n");
pcourse=course;
for(i=0; i<5; i++)
scanf("%s",&course[i]);
printf("input NO. and score:/n");
printf("NO.");
for(i=0; i<5; i++)
printf(",%s",course[i]);
printf("/n");
pnum=&num[0];
pscore=&score[0][0];
for(i=0; i<4; i++)
{
scanf("%d",pnum+i); //这是对每一个人进行编号;只需要给四个值;所以只能放在此处;
for(j=0; j<5; j++)
scanf("%f",pscore+5*i+j); //分数要给20个值;
}
paver=&aver[0];
printf("/n/n");
avsco(pscore,paver);
avcour1(pcourse,pscore);
printf("/n/n");
fail2(pcourse,pnum,pscore,paver);
printf("/n/n");
good(pcourse,pnum,pscore,paver);
return 0;
}
void avsco(float *pscore,float *paver)
{
int i,j;
float sum,average;

for(i=0; i<4; i++)
{sum=0.0;
for(j=0; j<5; j++)
sum=sum+(*(pscore+5*i+j)); //在这个等式当中,*(pscore+5*i+j)一定要加括号;
average=sum/5;
*(paver+i)=average;
}
}
//此处不能将char (*pcourse)[10]写成*(pcourse)[10];否则link严重错误;
void avcour1(char (*pcourse)[10],float *pscore)//此处声明不是char course[5][10],而是char (*pcousre)[10]);
{
int i;
float sum,average1;
sum=0.0; //sum需要初始化为0.0;
for(i=0; i<4; i++)
sum=sum+(*(pscore+5*i));
average1=sum/4;
printf("the first course %s average score is %f",*pcourse,average1);
}
void fail2(char course[5][10],int num[],float *pscore,float aver[4])//因为采用数组指针course[i],所以不能用char *(pcourse)[10];
{
int i,j,k,label;
printf("==================Student who is fail in two couses===================/n");
printf("NO.");
for(i=0; i<5; i++)
printf("%11s",course[i]); //因为要用course[i]输出课程名称,所以不能声明char *(pcourse)[10]; 只能是char course[5][10];
printf("average/n");
for(i=0; i<4; i++)
{label=0; //每个人的不及格的course 计数;
for(j=0; j<5; j++)
if(*(pscore+5*i+j)<60) label++;
if(label>=2)//只能在label>=2中输出每个人的成绩和平均分;
{
printf("%d",num[i]);
for(k=0; k<5; k++)
printf("%11.2f",*(pscore+5*i+k)); //输出这个人的课程成绩;
printf("%11.2f",aver[i]); //因为平均成绩已经算好,保存在aver[i]当中; 所以声明也适用aver[4];
}
}
}
void good(char course[5][10],int num[4],float *pscore,float aver[4])
{
int i,j,k,n;
printf("================Students whose score is good========/n");
printf("NO.");
for(i=0; i<5; i++)
printf("%11s",course[i]);
printf("average/n");
for(i=0; i<4; i++)
{n=0; //对每个人的成绩大于85计数;初值给0;
for(j=0; j<5; j++)
if(*(pscore+5*i+j)>85) n++;
if((n==5)||(aver[i]>90))//注意此处,aver[i]>90需要加括号;(aver[i]>90)找出每门课程成绩>85或者平均分大于90的学生;
{printf("%d",num[i]);
for(k=0; k<5; k++)
printf("%11.2f",*(pscore+5*i+k));
printf("%11.2f/n",aver[i]); //此处不能与上一句加{}括号,否则错误;
}
}
}

    推荐阅读