c语言题,输出班上48个同学的四门科目成绩并求平均值,求教

如题所述

// 定义学生结构体
typedef struct student
{
    char *name;
    int score1;
    int score2;
    int score3;
    int score4;
    struct student *next;
}STU;

STU *pHeadStudent; // 48个学生的单向链表中的首个学生结构体的指针,具体的单向列表的生成省略哦

直接写输出班上48个同学的四门科目成绩并求平均值
void fun(STU *pHeadStudent){
    STU *p = pHeadStudent;
    while (null != p){
        float avg = ((*p).score1 + (*p).score2  + (*p).score3  + (*p).score4)/4.0;
        printf("%s的第一门成绩为:%d,第二门成绩为:%d,第三门成绩为:%d,第四门成绩为:%d,平均分数为:%.2f\n", p->name, (*p).score1, (*p).score2, (*p).score3, (*p).score4, avg);
        p = p->next;
    }
}

温馨提示:答案为网友推荐,仅供参考
相似回答