实验4 输入四个人的年龄和姓名,排序后,按年龄,从小到大输出人员年龄及其姓名
#include<stdio.h> #include<stdlib.h> #include<string.h> main() { char s[255]; char name[][255]={"aaa","bbb","ccc","ddd"}; int i,j,t,age[50]={30,23,15,32}; for(i=0;i<3;i++) for(j=i+1;j<4;j++) if(age[i]>age[j]) { t=age[i]; age[i]=age[j]; age[j]=t; strcpy(s,name[i]); strcpy(name[i],name[j]); strcpy(name[j],s); } printf("按年龄从小到大排序为:\n"); for(i=0;i<4;i++) printf("%s %d\n",name[i],age[i]); system("PAUSE"); }