#include <stdio.h>
# define stuN 40
# define couN 4
void read(long stuID[],int sco[][couN],int n);
void AverS(int sumS[],float averS[],int n);
void AverC(int sumC[],float averC[],int n);
void output(long stuID[],int n,int sco[][couN],int sumC[],
int sumS[],float averC[],float averS[]);
main()
{
int n,sco[stuN][couN],sumS[stuN],sumC[couN];
long stuID[stuN];
float averS[stuN],averC[couN];
printf("请输入有多少学生参加考试:");
scanf("%d",&n);
printf("请按顺序输入他们的学号,语文,数学,英语,物理成绩:\n");
read(stuID,sco,n);
AverS(sumS,averS,n);
AverC(sumC,averC,n);
output(stuID,n,sco,sumC,sumS,averC,averS);
return;
}
void read(long stuID[],int sco[][couN],int n)/*录入学生学号与成绩*/
{
int i,j;
for(i=0;i<n;i++)
{
scanf("%ld",&stuID[i]);
for(j=0;j<couN;j++)
{
scanf("%d",&sco[i][j]);
}
}
}
void AverS(int sumS[],float averS[],int n,int sco[][couN])/*每位学生的总分与平均分*/
{
int i,j;
for(i=0;i<n;i++)
{
sumS[i]=0;
for(j=0;j<couN;j++)
{
sumS[i]=sumS[i]+sco[i][j];
}
averS[i]=sumS[i]/couN;
}
averS[i]=(float)sumS[i]/couN;
}
void AverC(int sumC[],float averC[],int n,int sco[][couN])/*每科的总分与平均分*/
{
int i,j;
for(i=0;i<4;i++)
{
sumC[i]=0;
for(j=0;j<n;j++)
{
sumC[i]=sumC[i]+sco[j][i];
}
averC[i]=(float)sumC[i]/n;
}
}
void output(long stuID[],int n,int sco[][couN],int sumC[],
int sumS[],float averC[],float averS[])/*输出*/
{
int i,j;
printf("stuID \t数学\t语文\t英语\t物理\t个人总分\t平均分\n");
for(i=0;i<n;i++)
{
printf("%10d\t",stuID[i]);
for(j=0;j<couN;j++)
{
printf("%4d\t",sco[i][j]);
}
printf("%8d\t%6.2f\n",sumS[i],averS[i]);
}
printf("每科总分 \t");
for(i=0;i<couN;i++)
{
printf("%4d\t",sumC[i]);
}
printf("\n每科平均分\t");
for(i=0;i<couN;i++)
{
printf("%4d\t",averC[i]);
}
printf("\n");
}
# define stuN 40
# define couN 4
void read(long stuID[],int sco[][couN],int n);
void AverS(int sumS[],float averS[],int n);
void AverC(int sumC[],float averC[],int n);
void output(long stuID[],int n,int sco[][couN],int sumC[],
int sumS[],float averC[],float averS[]);
main()
{
int n,sco[stuN][couN],sumS[stuN],sumC[couN];
long stuID[stuN];
float averS[stuN],averC[couN];
printf("请输入有多少学生参加考试:");
scanf("%d",&n);
printf("请按顺序输入他们的学号,语文,数学,英语,物理成绩:\n");
read(stuID,sco,n);
AverS(sumS,averS,n);
AverC(sumC,averC,n);
output(stuID,n,sco,sumC,sumS,averC,averS);
return;
}
void read(long stuID[],int sco[][couN],int n)/*录入学生学号与成绩*/
{
int i,j;
for(i=0;i<n;i++)
{
scanf("%ld",&stuID[i]);
for(j=0;j<couN;j++)
{
scanf("%d",&sco[i][j]);
}
}
}
void AverS(int sumS[],float averS[],int n,int sco[][couN])/*每位学生的总分与平均分*/
{
int i,j;
for(i=0;i<n;i++)
{
sumS[i]=0;
for(j=0;j<couN;j++)
{
sumS[i]=sumS[i]+sco[i][j];
}
averS[i]=sumS[i]/couN;
}
averS[i]=(float)sumS[i]/couN;
}
void AverC(int sumC[],float averC[],int n,int sco[][couN])/*每科的总分与平均分*/
{
int i,j;
for(i=0;i<4;i++)
{
sumC[i]=0;
for(j=0;j<n;j++)
{
sumC[i]=sumC[i]+sco[j][i];
}
averC[i]=(float)sumC[i]/n;
}
}
void output(long stuID[],int n,int sco[][couN],int sumC[],
int sumS[],float averC[],float averS[])/*输出*/
{
int i,j;
printf("stuID \t数学\t语文\t英语\t物理\t个人总分\t平均分\n");
for(i=0;i<n;i++)
{
printf("%10d\t",stuID[i]);
for(j=0;j<couN;j++)
{
printf("%4d\t",sco[i][j]);
}
printf("%8d\t%6.2f\n",sumS[i],averS[i]);
}
printf("每科总分 \t");
for(i=0;i<couN;i++)
{
printf("%4d\t",sumC[i]);
}
printf("\n每科平均分\t");
for(i=0;i<couN;i++)
{
printf("%4d\t",averC[i]);
}
printf("\n");
}