如何编写一个关于排序问题的简单的C程序??

来源:百度知道 编辑:UC知道 时间:2024/06/27 16:11:40
问题要求是输入关于学生的关键字,输出学生各门课成绩,能够送小到大排序。

struct stu
{
char name[20];
long number;
float score[4];
};
struct stu student[4];

void input(struct stu arr[],int n)
{
int i,j;
char temp[30];
for (i=0;i<n;i++)
{
gets(arr[i].name);
gets(temp);
arr[i].number=atol(temp);
for(j=0;j<4;j++)
{
gets(temp);
arr[i].score[j]=atof(temp);
}
}
}
void aver(struct stu arr[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
arr[i].score[3]=0;
for(j=0;j<3;j++)
{
arr[i].score[3]=arr[i].score[3]+arr[i].score[j];
arr[i].score[3]=arr[i].score[3]/3;
}
}
}
void order(struct stu arr[],int n)
{
struct stu temp;
int i,j;
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
if(arr[j].score[3]>arr[j+1].score[3])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}