1.结构体数组
代码:
#include<myhead.h>
struct Stu
{
char name[100];
int age;
double score;
};
int main(int argc, const char *argv[])
{
int i,j;
struct Stu t={"z",1,1};
struct Stu arr[4]={{"甲乙",12,98},{"陈二",13,77},{"张三",16,86},{"李四",18,66}};
for(i=1;i<4;i++)
{
for(j=0;j<4-i;j++)
{
if(arr[j].score>arr[j+1].score)
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
for(i=0;i<4;i++)
{
printf("%s %d %lf\n",arr[i].name,arr[i].age,arr[i].score);
}
return 0;
}