[练习9-2]人的出生日期由...

人的出生日期由年、月、日组成,请在例9-1中的学生信息结构中增加一个成员:出生日期,用嵌套定义的方式重新定义该结构类型

#include <stdio.h>

struct birth{
    int year, month, day;
};

struct student{
    int num;
    char name[10];
    struct birth birth;
    int computer, english, math;
    double average;
};

int main(void){
    int i, n;
    struct student max, stu;
    printf("Input n:");
    scanf("%d", &n);
    printf("Input the student's number, name and course socres
");
    for (i = 1; i <= n; i++) {
        printf("No.%d:", i);
        scanf("%d%s%d%d%d", &stu.num, stu.name, &stu.math, &stu.english, &stu.computer);
        stu.average = (stu.math+stu.english+stu.computer) / 3.0;
        if (i == 1) {
            max = stu;
        }else if(max.average < stu.average){
            max = stu;
        }
    }
    
    printf("num:%d, name:%s, average:%2lf
", max.num, max.name, max.average);
    
    return 0;
}
原文地址:https://www.cnblogs.com/sidianok/p/15311071.html