是中间的排序代码有问题,if(stu[j].ly>stu[j].ly)应该改为if(stu[j].ly>stu[j+1].ly),我简单的修改了一下。
#include <stdio.h>
#define N 10
struct student
{
int ID;
int ly;
};
int main()
{
struct student stu[N]={{1,52},{2,92},{3,14},{4,48},{5,95},{6,0},{7,25},{8,74},{9,36},{10,59}};
struct student t;
int i,j;
for(i=0;i<N-1;i++)
{
for(j=0;j<N-i-1;j++)
{
if(stu[j].ly>stu[j+1].ly)
{
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
}
}
for(i=0;i<N;i++)
{
printf("学号:%d 成绩:%d\n",stu[i].ID, stu[i].ly);
}
return 0;
}