2条回答 默认 最新
- qfl_sdu 2021-06-29 09:52关注
代码如下,如有帮助,请采纳一下,谢谢。
#include <stdio.h> #include <stdlib.h> #include <string.h> struct StNode { int num; char name[20]; int score; StNode* next; }; int main() { int num,score,i; char name[20]={0}; struct StNode* head,*tmp,*p,*max; head = (struct StNode*)malloc(sizeof(struct StNode)); printf("请输入学生1的学号:"); scanf("%d",&num); printf("请输入学生1的姓名:"); scanf("%s",name); printf("请输入学生1的成绩:"); scanf("%d",&score); head->num = num; strcpy(head->name,name); head->score = score; head->next = 0; p = head; for (i=1;i<5;i++) { tmp = (struct StNode*)malloc(sizeof(struct StNode)); printf("请输入学生%d的学号:",i+1); scanf("%d",&num); printf("请输入学生%d的姓名:",i+1); scanf("%s",name); printf("请输入学生%d的成绩:",i+1); scanf("%d",&score); tmp->num = num; strcpy(tmp->name,name); tmp->score = score; tmp->next = 0; p->next = tmp; p = tmp; } //遍历并查找最大值 p = head; max = head; while(p) { if (p->score > max->score) { max = p; } p = p->next; } printf("成绩最大的学生信息为:%d %s %d\n",max->num,max->name,max->score); //释放资源 p = head; while(p) { tmp = p->next; free(p); p = tmp; } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 c程序不知道为什么得不到结果
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置