# C语言习题 学生成绩

C语言习题 学生成绩

5门课的名称
4个学生的学号和5门课成绩

``````english math c++ chinese art
1001 80 90 100 70 50
1002 59 60 70 60 43
1003 90 100 85 90 90
1004 85 86 89 90 88``````

``````course 1:english,average score:78.50
======Student who failed in two courses======
NO.english math c++ chinese art average
1002 59.00 60.00 70.00 60.00 43.00 58.40
======Students whose score is good======
NO.english math c++ chinese art average
1003 90.00 100.00 85.00 90.00 90.00 91.00``````

``````#include<stdio.h>
void avsco(float *pscore,float *paver)
{
int i,j;
float S,ave;
for(i=0;i<4;i++)
{
S=0.0;
for(j=0;j<5;j++)
{
S+=(*(pscore+5*i+j));
ave=S/5;
*(paver+i)=ave;
}
}
}
void avcour1(char (*pcourse)[10],float *pscore)
{
int i;
float S,ave1;
S=0.0;
for(i=0;i<4;i++)
S+=(*(pscore+5*i));
ave1=S/4;
printf("course 1:%s,average score:%.2f\n",*pcourse,ave1);
}

void fail2(char course[5][10],int num[],float *pscore,float aver[4])
{
int i,j,k,l;
printf("======Student who failed in two courses======\n");
printf("NO.");
for(i=0;i<5;i++)
printf("%s ",course[i]);
printf("average\n");
for(i=0;i<4;i++)
{
l=0;
for(j=0;j<5;j++)
if(*(pscore+5*i+j)<60.0) l++;
if(l>=2)
{
printf("%d ",num[i]);
for(k=0;k<5;k++)
printf("%.2f ",*(pscore+5*i+k));
printf("%.2f\n",aver[i]);
}
}
}

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("%s ",course[i]);
printf("average\n");
for(i=0;i<4;i++)
{
n=0;
for(j=0;j<5;j++)
if(*(pscore+5*i+j)>85.0) n++;
if((n==5)||(aver[i]>=90))
{
printf("%d ",num[i]);
for(k=0;k<5;k++)
printf("%.2f ",*(pscore+5*i+k));
printf("%.2f\n",aver[i]);
}
}

}

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,*pnum,num[4];
float score[4][5],aver[4],*pscore,*paver;
char course[5][10],(*pcourse)[10];
pcourse=course;
for (i=0; i<5; i++)
scanf("%s",course[i]);
pscore=&score[0][0];
pnum=&num[0];
for (i=0; i<4; i++)
{
scanf("%d",pnum+i);
for (j=0; j<5; j++)
scanf("%f",pscore+5*i+j);
}
paver=&aver[0];
avsco(pscore,paver);
avcour1(pcourse,pscore);
fail2(pcourse,pnum,pscore,paver);
good(pcourse,pnum,pscore,paver);
return 0;
}
``````

``````#include<stdio.h>
void avsco(float *pscore,float *paver)
{
int i,j;
float S,ave;
for(i=0;i<4;i++)
{
S=0.0;
for(j=0;j<5;j++)
{
S+=(*(pscore+5*i+j));
ave=S/5;
*(paver+i)=ave;
}
}
}
void avcour1(char (*pcourse)[10],float *pscore)
{
int i;
float S,ave1;
S=0.0;
for(i=0;i<4;i++)
S+=(*(pscore+5*i));
ave1=S/4;
printf("course 1:%s,average score:%.2f\n",*pcourse,ave1);
}

void fail2(char course[5][10],int num[],float *pscore,float aver[4])
{
int i,j,k,l;
printf("======Student who failed in two courses======\n");
printf("NO.");
for(i=0;i<5;i++)
printf("%s ",course[i]);
printf("average\n");
for(i=0;i<4;i++)
{
l=0;
for(j=0;j<5;j++)
if(*(pscore+5*i+j)<60.0) l++;
if(l>=2)
{
printf("%d ",num[i]);
for(k=0;k<5;k++)
printf("%.2f ",*(pscore+5*i+k));
printf("%.2f\n",aver[i]);
}
}
}

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("%s ",course[i]);
printf("average\n");
for(i=0;i<4;i++)
{
n=0;
for(j=0;j<5;j++)
if(*(pscore+5*i+j)>85.0) n++;
if((n==5)||(aver[i]>=90))
{
printf("%d ",num[i]);
for(k=0;k<5;k++)
printf("%.2f ",*(pscore+5*i+k));
printf("%.2f\n",aver[i]);
}
}

}

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,*pnum,num[4];
float score[4][5],aver[4],*pscore,*paver;
char course[5][10],(*pcourse)[10];
pcourse=course;
for (i=0; i<5; i++)
scanf("%s",course[i]);
pscore=&score[0][0];
pnum=&num[0];
for (i=0; i<4; i++)
{
scanf("%d",pnum+i);
for (j=0; j<5; j++)
scanf("%f",pscore+5*i+j);
}
paver=&aver[0];
avsco(pscore,paver);
avcour1(pcourse,pscore);
fail2(pcourse,pnum,pscore,paver);
good(pcourse,pnum,pscore,paver);
return 0;
}
``````