C语言填空:结构体填空

#include <stdio.h>
//->是一个整体,它是用于指向结构体子数据的指针,用来取子数据。
//换种说法,如果我们在C语言中定义了一个结构体,然后申明一个指针指向这个结构体,
//那么我们要用指针取出结构体中的数据,就要用到->。
//计算四位学生的平均成绩,保存在结构体中,然后列表输出这些学生信息 
struct STUDENT
{
    char name[16];int math;int english; int computer;float average;
};
void getaverage(struct STUDENT *pst)
{
    int sum=0;
    sum=【1】;
    pst->average=sum/3.0;
}
main()
{
    int i;
    struct STUDENT st[4]={{"AAAAA",99,98,97},{"BBBBB",96,95,94},{"CCCCC",93,92,91},{"DDDD",68,68,69}};
    printf("NAME\tMath\tEnglish\tComputer\tAverage\n");
    for(i=0;i<4;i++)
    getaverage(【1】);
    for(i=0;i<4;i++)
    {
        printf("%s\t%d\t%d\t%d\t%f\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average);
    }
    getchar();
}

 

#include <stdio.h>
//->是一个整体,它是用于指向结构体子数据的指针,用来取子数据。
//换种说法,如果我们在C语言中定义了一个结构体,然后申明一个指针指向这个结构体,
//那么我们要用指针取出结构体中的数据,就要用到->。
//计算四位学生的平均成绩,保存在结构体中,然后列表输出这些学生信息 
struct STUDENT
{
    char name[16];int math;int english; int computer;float average;
};
void getaverage(struct STUDENT *pst)
{
    int sum=0;
    sum=sum+pst->math+pst->english+pst->computer;
    pst->average=sum/3.0;
}
main()
{
    int i;
    struct STUDENT st[4]={{"AAAAA",99,98,97},{"BBBBB",96,95,94},{"CCCCC",93,92,91},{"DDDD",68,68,69}};
    printf("NAME\tMath\tEnglish\tComputer\tAverage\n");
    for(i=0;i<4;i++)
    getaverage(&st[i]);
    for(i=0;i<4;i++)
    {
        printf("%s\t%d\t%d\t%d\t%f\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average);
    }
    getchar();
}
#include <stdio.h>
//https://www.renrendoc.com/paper/206978342.html
//计算四位学生的平均成绩,保存在结构体中,然后列表输出这些学生信息 
struct STUDENT
{
    char name[16];int math;int english; int computer;float average;
};
void getaverage(struct STUDENT *pst)
{
    int sum=0;
    sum=sum+pst->math+pst->english+pst->computer;
    pst->average=sum/3.0;
}
main()
{
    int i;
    struct STUDENT st[4]={{"AAAAA",99,98,97},{"BBBBB",96,95,94},{"CCCCC",93,92,91},{"DDDD",68,68,69}};
    printf("NAME\tMath\tEnglish\tComputer\tAverage\n");
    for(i=0;i<4;i++)
    {st[i].average=(st[i].math+st[i].english+st[i].computer)/3.0;
    printf("%s\t%d\t%d\t%d\t%f\n",st[i].name,st[i].math,st[i].english,st[i].computer,st[i].average);
}
    getchar();
}

 

 

posted @ 2023-02-08 21:00  myrj  阅读(69)  评论(0编辑  收藏  举报