#include<stdio.h>
struct Date
{
int year;
int month;
int day;
};
struct Student
{
int numble;
int age;
char name[20];
char sex[8];
float score;
struct Date birthday;
};
void main()
{
struct Student stu[3] =
{
{14259,21,"ANNA","Female",96,{1994,03,05}},
{14567,20,"MILK","Male",95,{1995,07,25}},
{14325,22,"TED","Male",91,{1993,01,05}}
};
int i,j;
struct Student temp;
printf("学号 年龄 姓名 性别 成绩 生日\n");
for(i=0;i<3;i++)
{
printf("%d %d %s %s %.2f %d/%d/%d\n",
stu[i].numble,stu[i].age,stu[i].name,stu[i].sex,stu[i].score,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
}
printf("按照成绩排序后的名单:\n");
for(j=0;j<3;j++)
{
for(i=0;i<3-j;i++)
{
if(stu[i].score > stu[i+1].score)
{
temp = stu[i];
stu[i] = stu[i+1];
stu[i+1] = temp;
}
}
}
for(i=0;i<3;i++)
{
printf("%d %d %s %s %.2f %d/%d/%d\n",
stu[i].numble,stu[i].age,stu[i].name,stu[i].sex,stu[i].score,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
}
}
这是代码,排序后的第一个数组显示乱码。
求大神解救~~~~