#include <stdio.h>#include <string.h>
// 日期结构体定义struct data { int year, month, day;};
// 学生信息结构体定义struct std_info { char no[lbk]10[rbk]; char name[lbk]10[rbk]; char sex; struct data birthday; int score[lbk]4[rbk]; float ave;};
// 显示一个学生的信息void display(struct std_info student) { printf("Student Number: %s\n", student.no); printf("Student Name: %s\n", student.name); printf("Sex: %c\n", student.sex); printf("Birthday: %d-%d-%d\n", student.birthday.year, student.birthday.month, student.birthday.day); printf("Scores: "); for (int i = 0; i < 4; i++) { printf("%d ", student.score[lbk]i[rbk]); } printf("\nAverage: %.2f\n", student.ave);}
// 输入一个学生的信息void input(struct std_info *student) { printf("Enter student number: "); scanf("%s", student->no); printf("Enter student name: "); scanf("%s", student->name); printf("Enter sex (M/F): "); scanf(" %c", &student->sex); printf("Enter birthday (YYYY-MM-DD): "); scanf("%d-%d-%d", &student->birthday.year, &student->birthday.month, &student->birthday.day); printf("Enter scores for 4 subjects: "); for (int i = 0; i < 4; i++) { scanf("%d", &student->score[lbk]i[rbk]); } student->ave = 0; for (int i = 0; i < 4; i++) { student->ave += student->score[lbk]i[rbk]; } student->ave /= 4;}
int main() { struct std_info students[lbk]3[rbk]; // 假设我们需要输入3名学生的信息
// 输入学生信息 for (int i = 0; i < 3; i++) { printf("\nInput information for student %d:\n", i + 1); input(&students[lbk]i[rbk]); }
// 显示学生信息 for (int i = 0; i < 3; i++) { printf("\nStudent %d Information:\n", i + 1); display(students[lbk]i[rbk]); }
return 0;}
// 日期结构体定义struct data { int year, month, day;};
// 学生信息结构体定义struct std_info { char no[lbk]10[rbk]; char name[lbk]10[rbk]; char sex; struct data birthday; int score[lbk]4[rbk]; float ave;};
// 显示一个学生的信息void display(struct std_info student) { printf("Student Number: %s\n", student.no); printf("Student Name: %s\n", student.name); printf("Sex: %c\n", student.sex); printf("Birthday: %d-%d-%d\n", student.birthday.year, student.birthday.month, student.birthday.day); printf("Scores: "); for (int i = 0; i < 4; i++) { printf("%d ", student.score[lbk]i[rbk]); } printf("\nAverage: %.2f\n", student.ave);}
// 输入一个学生的信息void input(struct std_info *student) { printf("Enter student number: "); scanf("%s", student->no); printf("Enter student name: "); scanf("%s", student->name); printf("Enter sex (M/F): "); scanf(" %c", &student->sex); printf("Enter birthday (YYYY-MM-DD): "); scanf("%d-%d-%d", &student->birthday.year, &student->birthday.month, &student->birthday.day); printf("Enter scores for 4 subjects: "); for (int i = 0; i < 4; i++) { scanf("%d", &student->score[lbk]i[rbk]); } student->ave = 0; for (int i = 0; i < 4; i++) { student->ave += student->score[lbk]i[rbk]; } student->ave /= 4;}
int main() { struct std_info students[lbk]3[rbk]; // 假设我们需要输入3名学生的信息
// 输入学生信息 for (int i = 0; i < 3; i++) { printf("\nInput information for student %d:\n", i + 1); input(&students[lbk]i[rbk]); }
// 显示学生信息 for (int i = 0; i < 3; i++) { printf("\nStudent %d Information:\n", i + 1); display(students[lbk]i[rbk]); }
return 0;}