*/输入10个学生5门课的成绩,分别用函数实现下列功能:
1>计算每个学生的平均分。
2>计算每门课的平均分。
3>找出所有50个分数中最高的分数所对应的学生和课程。/*
#include
#include
#include
#include
typedef struct Student
{
char name[10];
int math;
int english;
int chinese;
int Seril;
struct Student *pNext;
}Stu,*pStu;
void Init_Student(pStu pHead);
pStu Creat_Student()
{
int i = 0;
int num = 0;
pStu pM = NULL;
pStu pHead = (pStu)malloc(sizeof(Stu));
if(pHead==NULL)
{
printf("未能开辟空间!\n");
exit(-1);
}
printf("请输入你要输入学生信息的个数:");
scanf("%d",&num);
if (num
{
printf("你没有要插入学生!\n");
exit(-1);
}
pM = pHead;
pHead->pNext = NULL;
for (i = 0; i
{
pStu student = (pStu)malloc(sizeof(Stu));
pM->pNext= student;
student->pNext = NULL;
pM = student;
}
free(pM);
return pHead;
}
void Init_Student(pStu pHead)
{
int i = 1;
pStu phead = pHead;
printf("请依次输出学生信息(姓名\\语文成绩\\数学成绩\\英语成绩):\n");
while (1)
{
phead = phead->pNext;
printf("第%d个:\n",i);
scanf("%s", phead->name);
scanf("%d", &phead->chinese);
scanf("%d", &phead->math);
scanf("%d", &phead->english);
phead->Seril = i;
i++;
if (phead->pNext == NULL)
break;
}
free(phead);
}
void Count_Average(pStu pHead)
{
int avr_ch = 0;
int avr_en = 0;
int avr_ma = 0;
int avr_stu = 0;
int num = 1;
pStu phead = pHead;
while (1)
{
avr_stu = 0;
phead = phead->pNext;
avr_ch = avr_ch+phead->chinese;
avr_en = avr_en+phead->english;
avr_ma = avr_ma+phead->math;
avr_stu = avr_stu + phead->chinese + phead->english + phead->math;
printf("%s的所有成绩的平均分为:%d\n", phead->name, avr_stu / 3);
if (phead->pNext == NULL)
break;
num++;
}
printf("所有人语文成绩平均分为:%d\n", avr_ch / num);
printf("所有人数学成绩平均分为:%d\n", avr_ma / num);
printf("所有人英语成绩平均分为:%d\n", avr_en / num);
free(phead);
}
void Show_Hig_scr_stu(pStu pHead)
{
pStu phead = pHead->pNext;
int seril = 1;
int hig_scr1 = 0;
int hig_scr2 = 0;
while (1)
{
int high = 0;
if (phead->pNext == NULL)
break;
high = (phead->chinese >= phead->english ? phead->chinese : phead->english);
hig_scr1 = high >= phead->math ? high : phead->math;
high = (phead->pNext->chinese >= phead->pNext->english ? phead->pNext->chinese :
phead->pNext->english);
hig_scr2 = high >= phead->pNext->math ? high : phead->pNext->math;
if (hig_scr1
{
seril = phead->pNext->Seril;
phead = phead->pNext;
if (phead->pNext == NULL)
break;
}
else
phead->pNext = phead->pNext->pNext;
}
phead = pHead->pNext;
while (1)
{
if (phead->Seril == seril)
{
if (phead->chinese>=phead->math&&phead->chinese>=phead->english)
printf("%s的语文成绩最高为:%d\n", phead->name, phead->chinese);
if (phead->chinese <= phead->math&&phead->math >= phead->english)
printf("%s的数学成绩最高为:%d\n", phead->name, phead->math);
if (phead->chinese <= phead->english&&phead->math <= phead->english)
printf("%s的英语成绩最高为:%d\n", phead->name, phead->english);
break;
}
phead = phead->pNext;
}
free(phead);
}
int main()
{
pStu phead = (pStu)malloc(sizeof(Stu));
phead = Creat_Student();
Init_Student(phead);
Count_Average( phead);
Show_Hig_scr_stu(phead);
return 0;
}