#include<stdio.h>
#define N 5
struct STUDENT { int num,sex,age; char name[20]; float score; };
void input(struct STUDENT *a,int n) { int i;
printf("请输入学生信息:姓名 性别(0男1女) 年龄 成绩\n");
for ( i=0;i<n;i++ ) scanf("%d%s%d%d%f",&a[i].num,a[i].name,&a[i].sex,&a[i].age,&a[i].score);
}
void output(struct STUDENT *a,int n,int *index) { int i,k;
for ( i=0;i<N;i++ ) {
k=index[i];
printf("%d\t%-10s\t%s %2d %.1f\n",
a[k].num,a[k].name,( a[k].sex==0 )?("男"):("女"),
a[k].age,a[k].score);
}
}
void main() { int i,j,k,index[N]; struct STUDENT a[N];
input(a,N); for ( i=0;i<N;i++ ) index[i]=i;
for ( i=0;i<N-1;i++ ) //用索引对成绩进行排序
for ( j=i+1;j<N;j++ )
if ( a[index[i]].score<a[index[j]].score )
{ k=index[i]; index[i]=index[j]; index[j]=k; }
output(a,N,index);
}
温馨提示:答案为网友推荐,仅供参考