关于《新人求助,自己三天没解决了》的帖子我还写了个程序,不过这个程序就没错误,我也发上来
#include<stdio.h>#include<malloc.h>
struct student
{
char name[100];
char age;
float score;
};
int main (void)
{
struct student * parr;
int len ;
int i;
int j;
struct student t;
printf("请输入学生的个数:\n");
printf("人数= ");
scanf("%d",&len);
parr = (struct student *) malloc(len * sizeof(struct student ));
for(i = 0; i <len; i++ )
{
printf("请输入第%d个学生的信息\n",i+1);
printf("姓名=");
scanf("%s",parr[i].name);
printf("年龄=");
scanf("%d",&parr[i].age);
printf("分数=");
scanf("%f",&parr[i].score);
}
for(i = 0; i < len-1; ++i)
for(j = 0; j < len-1-i; ++j)
{
if(parr[j].score < parr[j+1].score)
{
t = parr[j];
parr[j] = parr[i+j];
parr[j+1] = t;
}
}
printf("以下为学生排名信息:\n");
printf("********************************************************************************\n");
for(i = 0; i < len; i++)
{
printf("第%d名学生的信息如下:",i+1);
printf("姓名:%s 年龄:%d 成绩:%f\n",parr[i].name, parr[i].age, parr[i].score);
}
return 0;
}