*/输入10个学生5门课的成绩,分别用函数实现下列功能: 1>计算每个学生的平均分。 2>计算每门课的平均分。 3>找出所有50个分数中最高的分数所对应的学生和课程。/* #include<stdio.h> #include<malloc.h> #include<string.h> #include<stdlib.h> 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 < 1) { printf("你没有要插入学生!\n"); exit(-1); } pM = pHead; pHead->pNext = NULL; for (i = 0; i < num ; 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 < hig_scr2) { 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; }
c语言 链表基础
原创
©著作权归作者所有:来自51CTO博客作者霜柒染的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
4.带头节点的双链表的实现(C语言)
双链表基本运算的代码实现,前插、后插操作
双链表 头结点 插入操作 删除操作 -
C语言链表
c语言链表
链表 c语言 结点 头结点 -
c语言:链表排序, 链表反转
链表排序;链表反转
数据 倒序 链表 -
输出链表(c语言)
输出链表描述格式样例题解及详细注释描685, 2)(170, 0)(488, 3)(
数据结构 链表 c语言 数据 头结点 -
C语言--链表基础模板
1.建立结构体 2.空链表的创建 3.添加结点 4.删除结点 5.插入结点 应用
结点 链表 赋值 删除结点 微信