C语言编程题 输入某班20个学生的姓名级数学、英语成绩。建立一个链表,计算并输出每个学生的平均分
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
#include<stdio.h>
#define MAX_NUM 20
using namespace std;
struct Stu{
char name[10];
int m;
int e;
};
struct Node{
Stu s;
Node* next;
};
int main()
{
Stu* st=new Stu;
scanf("%s %d %d",&st->name,&st->m,&st->e);
Node* first=new Node;
first->next=NULL;
first->s=*st;
int count=MAX_NUM-1;
Node *p1,*p2;
p1=p2=first;
while(count--)
{
scanf("%s %d %d",&st->name,&st->m,&st->e);
p2=new Node;
p2->next=NULL;
p2->s=*st;
p1->next=p2;
p1=p1->next;
}
p1=first;
float mark=0;
char* Mname;
while(p1!=NULL)
{
if(mark<(float)(p1->s.e+p1->s.m)/2)
{
mark=(float)(p1->s.e+p1->s.m)/2;
Mname=p1->s.name;
}
printf("Name:%s ,Average marks:%.2f\n",p1->s.name,(float)(p1->s.e+p1->s.m)/2);
p1=p1->next;
}
printf("Name:%s ,Max Average marks:%.2f\n",Mname,mark);
delete p1;
delete p2;
delete first; //这里我没有释放全部空间,只是头节点,我觉得这样能满足你的要
return 0; //求,另外用双重for循环可逐个逐个结点释放,这里我就不写了
}
#define MAX_NUM 20
using namespace std;
struct Stu{
char name[10];
int m;
int e;
};
struct Node{
Stu s;
Node* next;
};
int main()
{
Stu* st=new Stu;
scanf("%s %d %d",&st->name,&st->m,&st->e);
Node* first=new Node;
first->next=NULL;
first->s=*st;
int count=MAX_NUM-1;
Node *p1,*p2;
p1=p2=first;
while(count--)
{
scanf("%s %d %d",&st->name,&st->m,&st->e);
p2=new Node;
p2->next=NULL;
p2->s=*st;
p1->next=p2;
p1=p1->next;
}
p1=first;
float mark=0;
char* Mname;
while(p1!=NULL)
{
if(mark<(float)(p1->s.e+p1->s.m)/2)
{
mark=(float)(p1->s.e+p1->s.m)/2;
Mname=p1->s.name;
}
printf("Name:%s ,Average marks:%.2f\n",p1->s.name,(float)(p1->s.e+p1->s.m)/2);
p1=p1->next;
}
printf("Name:%s ,Max Average marks:%.2f\n",Mname,mark);
delete p1;
delete p2;
delete first; //这里我没有释放全部空间,只是头节点,我觉得这样能满足你的要
return 0; //求,另外用双重for循环可逐个逐个结点释放,这里我就不写了
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询