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

#define MAX_STUDENT 10

typedef struct { int id; // 学号 char name[20]; // 姓名 float score; // 分数 } Student;

Student student[MAX_STUDENT]; int count = 0;

void clearStudent(int index) { if (index < 0 || index >= count) { printf('Invalid index.\n'); return; } student[index].id = 0; strcpy(student[index].name, ''); student[index].score = 0; }

int main() { int i; for (i = 0; i < 3; i++) { printf('Input student %d's id, name and score: ', i + 1); scanf('%d %s %f', &student[i].id, student[i].name, &student[i].score); if (student[i].score >= 60) { printf('Student %d passed.\n', i + 1); printf('ID: %d, Name: %s, Score: %.1f\n', student[i].id, student[i].name, student[i].score); } else { printf('Student %d failed.\n', i + 1); } count++; }

int index;
printf('Input the index of student to clear: ');
scanf('%d', &index);
clearStudent(index);

for (i = 0; i < count; i++) {
    if (student[i].id != 0) {
        printf('ID: %d, Name: %s, Score: %.1f\n', student[i].id, student[i].name, student[i].score);
    }
}

return 0;

}

C语言学生信息管理:结构体数组、输入输出、函数封装

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

免费AI点我,无需注册和登录