<pre id=\"best-answer-content\" class=\"reply-text mb10\">我帮你改了下:
//你在使用数组前要先定义它
//而且你要比较的是p[]数组的大小,所以sort()参数你的错了
//而且你的改变p[].score时没有改变p[].num
#include\"stdio.h\"
struct person
{
int num;
float score;
};
void sort(struct person p[])
{
float t;
int a;
int i,j;
int h,k;
for(i=0;i14-1;i)
for(j=0;j14-i;j)
if(p[j].scorep[j 1].score)
{
t=p[j 1].score;
p[j 1].score=p[j].score;
p[j].score=t;
a = p[j 1].num;
p[j 1].num = p[j].num;
p[j].num = a;
}
for(h=1,k=0;k15,h=15;h,k)
{
printf(\"第%d名 %d 成绩 %.1f秒\\n\",h,p[k].num,p[k].score);
// printf(\"the %d ming %d de fen shu is %.2f\\n\",h,p[k].num,p[k].score);
}
}
void main()
{
struct person per[15]={{207,14.5f},{231,14.7f},
{153,15.1f},{278,15.5f},
{88,15.3f},{321,14.8f},
{166,14.2f},{302,14.5f},
{96,15.7f},{339,14.9f},
{77,15.1f},{276,13.9f},
{296,14.3f},{122,13.7f},
{156,15.2f}};
sort(per);
} |