...每个学生的数据包括学号、姓名、3门课的成绩,请看下面..._百度知...
发布网友
发布时间:2024-10-03 04:23
我来回答
共1个回答
热心网友
时间:2024-10-14 21:25
#include<stdio.h>
#include<malloc.h>
struct work{
int no;
char name[20];
int score[3];
struct work *next;
}node;
struct work *link(int n)
{
int i=1;
struct work *head ,*p1;
char a;
head = NULL;
while(n)
{
p1=(struct work*)malloc(sizeof(node));
printf("请输入第%d个学生信息",i++);
scanf("%d%s%d%d%d",&p1->no, p1->name, &p1->score[0], &p1->score[1], &p1->score[2]);
p1->next=head;
head=p1;
n--;
}
return head;
}
void main()
{
struct work *p,*head;
int i, sum[3] = {0};
head =link(3);
p=head;
int maxscore[3] = {0};
struct work *pmax[3];
while(p)
{
for (i = 0; i < 3; i++)
{
if (maxscore[i] < p->score[i])
{
maxscore[i] = p->score[i];
pmax[i] = p;
}
}
sum[0] += p->score[0];
sum[1] += p->score[1];
sum[2] += p->score[2];
p=p->next;
}
printf("第一门平均成绩:%f,第二门平均成绩:%f,第三门平均成绩:%f\n", sum[0] / (float)3, sum[1] / (float)3, sum[2] / (float)3);
printf("第一门最高分的学生信息:%d %s %d %d %d\n",pmax[0]->no, pmax[0]->name, pmax[0]->score[0], pmax[0]->score[1], pmax[0]->score[2]);
printf("第一门最高分的学生信息:%d %s %d %d %d\n",pmax[1]->no, pmax[1]->name, pmax[1]->score[0], pmax[1]->score[1], pmax[1]->score[2]);
printf("第一门最高分的学生信息:%d %s %d %d %d\n",pmax[2]->no, pmax[2]->name, pmax[2]->score[0], pmax[2]->score[1], pmax[2]->score[2]);
}