实验11-测试

#include<stdio.h>

struct student{

         int age;

         char name[10];

};

struct student stud[4];

 

 

int main(void)

{

         int i,j,index;

        

        

         struct student temp;

         printf("\nInput the student's age,name:\n");

         for(i=0;i<4;i++){

                   printf("No %d:",i+1);

                   scanf("%d%s",&stud[i].age,&stud[i].name);

         }

         for(i=0;i<4;++i){

                   index=i;

                   for(j=i+1;j<4;j++)

                            if(stud[j].age<stud[index].age)

                                     index=j;

                            temp=stud[index];

                            stud[index]=stud[i];

                            stud[i]=temp;

         }

        

     

         for(i=3;i>=0;i--)

                   printf("%d %s\n",stud[i].age,stud[i].name);

         return 0;

}

 

posted @ 2013-11-21 09:59  zhaoyang16  阅读(101)  评论(0编辑  收藏  举报