原来还可以这样
程序代码:
#include<stdio.h> struct Student { int num; char name[20]; float score[3]; }; void input(struct Student stu[]) { int i, j; for (i = 0; i < 5; i++) { printf("Input No.%d student's num and name\n", i + 1); scanf_s("%d%s", &stu[i].num, &stu[i].name, 20); for (j = 0; j < 3; j++) { printf("Input No.%d student's No.%d score\n", i + 1, j + 1); scanf_s("%f", &stu[i].score[j]); } } } void print(struct Student stu[]) { int i, j; printf("\nNo. name score1 score2 score3\n"); for (i = 0; i < 5; i++) { printf("%d %-10s", stu[i].num, stu[i].name); for (j = 0; j < 3; j++) printf("%10.2f ", stu[i].score[j]); printf("\n"); } } int main() { void input(struct Student stu[]); void print(struct Student stu[]); struct Student stu[5]; input(stu); print(stu); return 0; }