用C语言定义一个包含学生成绩(学号,姓名,成绩)的顺序表,读入相应的成绩信息来完成学生成绩表的创建。然后,(1)查找统计不及格的学生人数,(2)删除并以学号升序方式逐行输出不及格的学生信息。如果不存在不及格同学,则输出提示信息“not found”
时间: 2023-04-06 15:04:48 浏览: 89
可以回答这个问题。以下是代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
typedef struct {
int id;
char name[20];
int score;
} Student;
typedef struct {
Student data[MAX_SIZE];
int length;
} SeqList;
void create(SeqList *list);
int count_fail(SeqList list);
void delete_fail(SeqList *list);
int main() {
SeqList list;
create(&list);
int fail_num = count_fail(list);
if (fail_num == 0) {
printf("not found\n");
} else {
printf("fail_num: %d\n", fail_num);
delete_fail(&list);
}
return 0;
}
void create(SeqList *list) {
printf("input student number: ");
scanf("%d", &list->length);
printf("input student info (id, name, score):\n");
for (int i = 0; i < list->length; i++) {
scanf("%d %s %d", &list->data[i].id, list->data[i].name, &list->data[i].score);
}
}
int count_fail(SeqList list) {
int count = 0;
for (int i = 0; i < list.length; i++) {
if (list.data[i].score < 60) {
count++;
}
}
return count;
}
void delete_fail(SeqList *list) {
for (int i = 0; i < list->length; i++) {
if (list->data[i].score < 60) {
printf("%d %s %d\n", list->data[i].id, list->data[i].name, list->data[i].score);
for (int j = i; j < list->length - 1; j++) {
list->data[j] = list->data[j + 1];
}
list->length--;
i--;
}
}
}
阅读全文