C语言~~共用体、结构体与枚举类型

2025-03-10 01:54:51
推荐回答(2个)
回答1:

#include 
#include 
#include 

struct Date
{
    int year;
    int month;
    int day;
};
typedef struct st_person
{
    char name[10];
    char sex;
    struct Date birth;
    char ID[19];
    char email[60];
}Person ;
struct student
{
    int id;
    char name[10];
    float score;
};
int main()
{
    Person p[20];
    Person me;
    int i,idx;
    printf( "输入 me 的信息:(姓名 性别(m/f) 出生年 月 日 身份证号 邮箱:\n" );
    scanf( "%s %c %d %d %d %s %s", me.name, &me.sex, &me.birth.year,
            &me.birth.month, &me.birth.day, me.ID, me.email );
    printf( "姓名:%s 性别:%c 出生日期:%d年%d月%d日\n身份证号:%s\n邮箱:%s\n",
            me.name, me.sex, me.birth.year,
            me.birth.month, me.birth.day, me.ID, me.email );
    for( i=0; i<20; i++ )
    {
        printf( "输入第%d个人的信息:"\
                "(姓名 性别(m/f) 出生年 月 日 身份证号 邮箱:\n", i+1 );
        scanf( "%s %c %d %d %d %s %s", p[i].name, &p[i].sex, 
                &p[i].birth.year, &p[i].birth.month, &p[i].birth.day, 
                p[i].ID, p[i].email );
    }
    for( i=0; i<20; i++ )
    {
        if ( p[i].birth.year >=1990 && p[i].birth.year <=1995 )
            printf( "姓名:%s, 性别:%c\n", p[i].name, p[i].sex );
    }
    struct student stu[10];
    float max=0.0;
    for( i=0; i<10; i++ )
    {
        printf( "输入第%d个学生的学号 姓名 成绩:", i+1 );
        scanf( "%d %s %g", &stu[i].id, stu[i].name, &stu[i].score );
        if( max < stu[i].score )
        {
            max = stu[i].score;
            idx = i;
        }
    }

    printf( "max score: %d %s %g\n", stu[idx].id, stu[idx].name, stu[idx].score );
}

回答2:

看起来很麻烦的样子