关于学生成绩排序的问题
题目要求是对n个同学的成绩进行排序输入格式如下:
5
1001 67 89 70
1002 76 94 60
1003 89 60 97
1005 73 90 71
1006 78 60 94
5代表5个学生 2-6行第一个元素代表学生学号,后三个元素代表单科成绩,然后按照分数从高到低排序,输出结果应该如下:
1 1003 89 60 97 246 82
2 1005 73 90 71 234 78
3 1006 78 60 94 232 77
4 1002 76 94 60 230 76
5 1001 67 89 70 226 75
然而我的代码如下:
#include<stdio.h>
#include<stdlib.h>
void Input (int (*pscore)[4],int n);
void Sort(int *pscore,int n,int *pSum,int *pAver);
void Print(int (*pscore)[4],int n,int *pSum,int *pAver);
int Search(int (*pscore)[4],int n,int *pSum,int *pAver);
int main()
{
int score[100][4],Sum[100],Aver[100],n;
printf("Input the number of student:\n");
scanf("%d",&n);
if (n==0)
{
printf("wrong number!");
return 0;
}
Input(score,n);
Sort(score[0],n,Sum,Aver);
Print(score,n,Sum,Aver);
Search(score,n,Sum,Aver);
return 0;
}
void Input (int (*pscore)[4],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("Input student's ID and scores of Math, English, Physical:\n");
for(j=0;j<4;j++)
{
scanf("%d",*(pscore+i)+j);
}
}
}
void Sort(int *pscore,int n,int *pSum,int *pAver)
{
int i,j,temp=0;
for(i=0;i<n;i++)
{
pSum[i]=0;
for (j=1;j<4;j++)
{
pSum[i]=pSum[i]+pscore[i*4+j];
}
pAver[i]=pSum[i]/3;
}
for (i=0;i<n-1;i++)
{
for (j=i+1;j<n;j++)
{
if (pAver[j]>pAver[i])
{
temp=pAver[j];
pAver[j]=pAver[i];
pAver[i]=temp;
temp=pSum[j];
pSum[j]=pSum[i];
pSum[i]=temp;
temp=pscore[j*4+1];
pscore[j*4+1]=pscore[i*4+1];
pscore[i*4+1]=temp;
temp=pscore[j*4+2];
pscore[j*4+2]=pscore[i*4+2];
pscore[i*4+2]=temp;
temp=pscore[j*4+3];
pscore[j*4+3]=pscore[i*4+3];
pscore[i*4+3]=temp;
temp=pscore[j*4+0];
pscore[j*4+0]=pscore[i*4+0];
pscore[i*4+0]=temp;
}
}
}
}
void Print(int (*pscore)[4],int n,int *pSum,int *pAver)
{
int i;
printf("Number ID Math Eng Phy Sum Aver\n");
for (i=0;i<n;i++)
{
printf ("%d %d %d %d %d %d %d\n",i+1,*pscore[i*4+0],*pscore[i*4+1],*pscore[i*4+2],*pscore[i*4+3],pSum[i],pAver[i]);
}
}
int Search(int (*pscore)[4],int n,int *pSum,int *pAver)
{
int id,i,k=1,flag=0;
for(;;)
{
printf("Input the student's ID you want to search(exit by 0):");
scanf("%d",&id);
if(id!=0)
{
for(i=0;i<n;i++)
{
if (id==k*(*pscore[i*4+0]))
{
flag=1;
printf("Number ID Math Eng Phy Sum Aver\n");
printf("%d %d %d %d %d %d %d\n",i+1,*pscore[i*4+0],*pscore[i*4+1],*pscore[i*4+2],*pscore[i*4+3],pSum[i],pAver[i]);
}
}
if (flag==0)
{
printf("The ID doesn't exist!");
break;
}
}
if (id==0)
{
break;
}
}
return 0;
}
然后输出后是这样的结果
求教这是怎么回事啊