题目:编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包含num、name、scroe[3],用主函数输入这些记录,用print函数输出这些记录。
#include <stdio.h>
struct student
{
int num;
char name[10];
float score[3];
} stu[5];
void print(struct student s[]);
int main()
{
int i, j;
for (i = 0; i < 5; i++) {
printf("Please enter No.%d student num, name, score: ", i + 1);
scanf("%d %s", &stu[i].num, stu[i].name);
for (j = 0; j < 3; scanf("%f", &stu[i].score[j++]));
}
print(stu);
return 0;
}
void print(struct student s[])
{
int i, j;
for (i = 0; i < 5; printf("\n"), i++) {
printf("%d %-10s ", s[i].num, s[i].name);
for (j = 0; j < 3; printf("%.2f ", s[i].score[j++]));
}
}