C语言一个学生的基本信息:学号、姓名、性别、年龄、语文成绩、数学成绩、平均成绩,编程实现从键盘输入一个学生的信息,并打印输出此学生的所有信息。

用C语言把一个学生的基本信息:学号、姓名、性别、年龄、语文成绩、数学成绩、平均成绩,编程实现从键盘输入一个学生的信息,并打印输出此学生的所有信息。
利用上题定义的结构体定义一个结构体数组,存放3个同学的信息,编程实现从键盘输入3个同学的信息,计算平均成绩,并打印输出每个学生的学号、姓名和平均成绩。

img


#include<stdio.h>
#define N 3
typedef struct Student{
long long int id;
char name[20];
char sex[5];
float chinese;
float math;
float avg;
}Student;
Student student[N];
/**控制台录入信息*/
void insert(Student student[N])
{
    int i;
    for(i=0;i<N;i++)
    {
        printf("请输入第%d位学生的信息:\n",i+1);
        scanf("%lld %s %s %f %f",&student[i].id,student[i].name,student[i].sex,&student[i].chinese,&student[i].math);
        student[i].avg=(student[i].chinese+student[i].math)/(2*1.0);
    }
    
}
void print(Student student1[N])
{
   int i;
   for(i=0;i<N;i++)
   {
       printf("学号:%lld 姓名:%s 性别:%s 语文:%.2f 数学:%.2f 平均分:%.2f\n",
      student1[i].id,student1[i].name,student[i].sex,student1[i].chinese,student1[i].math,student1[i].avg);
   }
}
int main()
{
    insert(student);
    printf("学生信息如下:\n");
    print(student);
    return 0;
}

struct StudentScore{//单独做个类来存放成绩 
    int chinese;//语文 
    int algorithm;//数学 
    int average;//平均 
};

struct StudentInfo{//学生信息 
    char id[30];//学号
    char name[10];//名字
    char gender;//Male为男生,Female为女生
    int age;//年龄
    StudentScore score;//成绩 
};

结构体可以这样写