[Asm] 纯文本查看 复制代码/*通信录排序:建立一个通讯录,通讯录的结构记录包括:姓名 生日 电话号码;期中生日又包括三项:年 月 日。编写程序,定义一个嵌套的结构类型,输入n(n<10)个联系人的信息,
在按他们的的年龄从大到小的顺序依次输出其信息。试编写相应程序。
*/
// 此题的参考答案
#include
struct student
{
char name[10];
int birthday;//一开始我用char 发现不能比较(⊙o⊙)…
char Tel[30];
};
void studentsort(struct student s[],int t)
{
struct student map;//先再定义一个结构 方便判断语句的双值转换
int i,j;
for(i=1;i
{
for(j=0;j
{
//判断 大的数字年龄越小放在后面
if(s[j].birthday>s[j+1].birthday)
{
map=s[j+1];
s[j+1]=s[j];
s[j]=map;
}
}
}
}
int main()
{
int i,n;
printf("Enter your want to input how much information : ");
scanf("%d",&n);
//定义一个结构
struct student pop[n];
for(i=0;i
{
printf("Please input name birthday Tel ");
scanf("%s %d %s",&pop[i].name,&pop[i].birthday,&pop[i].Tel);
}
studentsort(pop,n);
//打印
for(i=0;i
{
printf("name:%s birthday:%d Tel:%s\n",pop[i].name,pop[i].birthday,pop[i].Tel);
}
return 0;
}