#include <stdio.h> #include <string.h>

struct Student { char id[13]; // 学号,12位加上字符串结束符 char name[20]; // 姓名,最长不超过19个字符 int age; // 年龄 };

int main() { int n; printf("请输入学生人数:"); scanf("%d", &n); struct Student students[n]; // 定义结构体数组 int max_age = 0; // 最大年龄 int max_index; // 最大年龄学生的下标 for (int i = 0; i < n; i++) { printf("请输入第%d个学生的信息(学号 姓名 年龄):", i + 1); scanf("%s %s %d", students[i].id, students[i].name, &students[i].age); if (students[i].age > max_age) { // 更新最大年龄学生的信息 max_age = students[i].age; max_index = i; } } printf("年龄最大的学生是:%s %s\n", students[max_index].id, students[max_index].name); return 0;

标签: 教育


原文地址: https://cveoy.top/t/topic/fDBP 著作权归作者所有。请勿转载和采集!