编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些数据,用print输出这些记录
编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些数据,用print输出这些记录
代码如下:
#include<stdio.h>
#define N 5
typedef struct student{//结构体类型名重定义
int num;//学生学号
char name[20];//学生姓名
float score[3]; //学生分数
}Student;
void print(Student stu[])//输出各个同学信息
{
for(int i=0;i<N;i++)
printf("学号:%d\n姓名:%s\n三科成绩:%.1f %.1f %.1f\n\n",
stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}
int main()
{
Student stu[N];//定义结构体数组
for(int i=0;i<N;i++)
{
scanf("%d %s %f %f %f",&stu[i].num,&stu[i].name,
&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
print(stu);
return 0;
}
还没有评论,来说两句吧...