这是我改好后的
谢谢大家的帮忙啊 thank you
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct student)
struct student {
char num[15];
long numb;
char name[20];
char sex[6];
float score1;
float score2;
float score3;
struct student*next;
};
int main() {
void print(struct student*head);
int n = 1;
struct student *head, *p1, *p2, *p0;
head = p1 = p2 = (struct student*) malloc(LEN);
p1->next = NULL;
scanf("%s", p1->num);
scanf("%s %s %f %f %f", p1->name, p1->sex, &p1->score1, &p1->score2,
&p1->score3);
p1->numb = atoi(p1->num);
for (;;) {
if (n > 1)
p2->next = p1;
p2 = p1;
n++;
p1 = (struct student*) malloc(LEN);
p1->next = NULL;
scanf("%s", p1->num);
p1->numb = atoi(p1->num);
if (p1->numb == 0)
break;
scanf("%s %s %f %f %f", p1->name, p1->sex, &p1->score1, &p1->score2,
&p1->score3);
}
printf("\n\n
输入的数据\n");
print(head);
for(p1=head;;p1=p1->next)
{
float a ;
a=p1->score1+p1->score2+p1->score3;
if(a>=240)
printf("\n%s %s %.1f\n",p1->num,p1->name,a/3);
if(p1->next==NULL)
break;
}
p0 = (struct student*) malloc(LEN);
p0->next = NULL;
printf("\n输入插入的学生信息\n");
scanf("%s %s %s %f %f %f", p0->num, p0->name, p0->sex, &p0->score1,
&p0->score2, &p0->score3);
p0->numb = atoi(p0->num);
for (p1 = head;; p1 = p1->next) {
if (p1->next != NULL && p1->numb < p0->numb
&& p1->next->numb > p0->numb) {
p0->next = p1->next;
p1->next = p0;
break;
}
if (p1->next == NULL && p1->numb < p0->numb) {
p0 = p1->next;
p0->next = NULL;
break;
}
if (head->numb > p0->numb) {
p0->next = head;
p0 = head;
break;
}
}
printf("\n\n
插入后\n");
print(head);
for (p2 = p1 = head;; p2 = p1, p1 = p1->next) {
if (head->score2 < 70)
head = head->next;
if (p1->score2 < 70 && p1->next != NULL)
p2->next = p1->next;
if (p1->score2 < 70 && p1->next == NULL)
p2->next = NULL;
if(p1->next==NULL)
break;
}
printf("\n\n
删除后\n");
print(head);
return 0;
}
void print(struct student*head) {
struct student*p1;
p1 = head;
if (p1 != NULL)
do {
printf("%s %s %s %.1f %.1f %.1f\n", p1->num, p1->name, p1->sex,
p1->score1, p1->score2, p1->score3);
p1 = p1->next;
} while (p1 != NULL);
}