#include
struct date{int year;int month;int day;}; //定义日期结构体类型
struct student
{ char name[20];
char sex;
struct date birth;
};
int compare(struct date x, struct date y)
{
if(x.year!=y.year)
return x.year - y.year;
if(x.month!=y.month)
return x.month - y.month;
return x.day - y.day;
}
int main()
{
struct student s[4],smallest;
char buffer[100];
int i;
for(i=0;i<4;i++)
{
printf("请输入第%d个学生的名字: ",i+1);
gets(s[i].name);
printf("请输入第%d个学生的性别(M/F): ",i+1);
scanf("%c",&s[i].sex);
gets(buffer);
printf("请输入第%d个学生的出生年份: ",i+1);
scanf("%d", &s[i].birth.year);
gets(buffer);
printf("请输入第%d个学生的出生月份: ",i+1);
scanf("%d", &s[i].birth.month);
gets(buffer);
printf("请输入第%d个学生的出生日期: ",i+1);
scanf("%d", &s[i].birth.day);
gets(buffer);
}
smallest = s[0];
for(i=1;i<4;i++)
{
if(compare(smallest.birth,s[i].birth)>0)
{
smallest = s[i];
}
}
printf("年龄最大的是: %s\n",smallest.name);
scanf("%d");
}
int compare(struct date x,struct date y)
{
if(x.year < y.year)
return -1;
else if(x.year > y.year)
return 1;
else
{
if(x.month < y.month)
return -1;
else if(x.month > y.month)
return 1;
else
{
if(x.day < y.day)
return -1;
else if(x.day > y.day)
return 1;
else return 0;
)
}