其实可以不用结构体做的,我这里刚写了一个类似的
#include<stdio.h>
int TotalPoint(int score[][3],int n);
int AveragePoint(int sum[],int n);
void Order();
void Print(int score[][3],int sum[],int aver[],int num[],int n);
int Find(int score[][3],int sum[],int aver[],int num[],int n);
int sr(int num[],int score[][3]);
int score[30][3];
int num[30];
int order[30];
int sum[30],aver[30];
int n;
int main()
{
n=sr(num,score);
TotalPoint(score,n);
AveragePoint(sum,n);
Print(score,sum,aver,num,n);
Find(score,sum,aver,num,n);
return 0;
}
int TotalPoint(int score[][3],int n)
{
int i;
for(i=0;i<=n;i++)
{
sum[i]=score[i][0]+score[i][1]+score[i][2];
}
return 0;
}
int AveragePoint(int sum[],int n)
{
int i;
for(i=0;i<=n;i++)
{
aver[i]=sum[i]/3;
}
return 0;
}
void Order()
{
int i,j,temp1,temp2,temp3,temp4,temp5,temp6;
for(i=0;i<n-1;i++)
{
for(j=0;j<n;j++)
{
if(sum[j]>sum[i])
{
temp1=sum[j];
sum[j]=sum[i];
sum[i]=temp1;
temp2=num[j];
num[j]=num[i];
num[i]=temp2;
temp3=aver[j];
aver[j]=aver[i];
aver[i]=temp3;
temp4=score[j][0];
score[j][0]=score[i][0];
score[i][0]=temp4;
temp5=score[j][1];
score[j][1]=score[i][1];
score[i][1]=temp5;
temp6=score[j][2];
score[j][2]=score[i][2];
score[i][2]=temp6;
}
}
}
}
void Print(int score[][3],int sum[],int aver[],int num[],int n)
{
int i,j;
printf("result:\n");
printf("number\t MT\t EN\t PH\t SUM\t AVER\n");
for(i=0;i<n;i++)
{
printf("%4d\t",num[i]);
for(j=0;j<3;j++)
{
printf("%4d\t",score[i][j]);
}
printf("%5d\t%6d\n",sum[i],aver[i]);
}
}
int Find(int score[][3],int sum[],int aver[],int num[],int n)
{
int i,a;
printf("enter num:");
scanf("%d",&a);
for(i=0;i<n;i++)
{
if(a==num[i])
{
printf("num is%d
sum is%d
aver is%d",num[i],sum[i],aver[i]);
}
}
}
int sr(int num[],int score[][3])
{
int i,j;
printf("please enter the total number of students\n");
scanf("%d",&n);
printf("enter number and score as MT EN PH\n");
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
for(j=0;j<3;j++)
{
scanf("%d",&score[i][j]);
}
}
return n;
}