欢迎来到天天文库
浏览记录
ID:12678440
大小:86.00 KB
页数:11页
时间:2018-07-18
《结构体与链表编程题及解答》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、结构体与共用体【程序1】题目:编写input()和output()函数输入,输出5个学生的数据记录。(用结构体设计,学生记录中包括学号、姓名、四门课程成绩)程序源代码:#include#defineN5structstudent{charnum[6];charname[8];intscore[4];}stu[N];voidinput(structstudentstu[]);voidprint(structstudentstu[]);voidmain(){input(stu);print(stu);}voidinput(structstudentstu[]){
2、inti,j;for(i=0;i3、e2Score3");for(i=0;i#defineN3structstudent{intnum;charname[20];intscore;}4、;voidmain(){inti;structstudents[N];/*定义结构体类型数组,长度100*/for(i=0;i5、ame,s[i].score);}【程序3】题目:创建一个链表。程序源代码:/*creatalist*/#include"stdlib.h"#include11#defineN3structlist{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head;intnum,i;intj;printf("pleaseinputnumbers==>");scanf("%d",&j);ptr=(link)malloc(sizeof(node));h6、ead=ptr;printf("pleaseenternumbers:");for(i=0;i<=j-1;i++){scanf("%d",&num);ptr->data=num;ptr->next=(link)malloc(sizeof(node));if(i==j-1)ptr->next=NULL;elseptr=ptr->next;}ptr=head;while(ptr!=NULL){printf("Thevalueis==>%d",ptr->data);ptr=ptr->next;}}=========================================7、=====================【程序4】题目:反向输出一个链表。 1.程序分析:2.程序源代码:/*reverseoutputalist*/#include"stdlib.h"#includestructlist11{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head,tail;intnum,i;intj;printf("pleaseinputn
3、e2Score3");for(i=0;i#defineN3structstudent{intnum;charname[20];intscore;}
4、;voidmain(){inti;structstudents[N];/*定义结构体类型数组,长度100*/for(i=0;i5、ame,s[i].score);}【程序3】题目:创建一个链表。程序源代码:/*creatalist*/#include"stdlib.h"#include11#defineN3structlist{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head;intnum,i;intj;printf("pleaseinputnumbers==>");scanf("%d",&j);ptr=(link)malloc(sizeof(node));h6、ead=ptr;printf("pleaseenternumbers:");for(i=0;i<=j-1;i++){scanf("%d",&num);ptr->data=num;ptr->next=(link)malloc(sizeof(node));if(i==j-1)ptr->next=NULL;elseptr=ptr->next;}ptr=head;while(ptr!=NULL){printf("Thevalueis==>%d",ptr->data);ptr=ptr->next;}}=========================================7、=====================【程序4】题目:反向输出一个链表。 1.程序分析:2.程序源代码:/*reverseoutputalist*/#include"stdlib.h"#includestructlist11{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head,tail;intnum,i;intj;printf("pleaseinputn
5、ame,s[i].score);}【程序3】题目:创建一个链表。程序源代码:/*creatalist*/#include"stdlib.h"#include11#defineN3structlist{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head;intnum,i;intj;printf("pleaseinputnumbers==>");scanf("%d",&j);ptr=(link)malloc(sizeof(node));h
6、ead=ptr;printf("pleaseenternumbers:");for(i=0;i<=j-1;i++){scanf("%d",&num);ptr->data=num;ptr->next=(link)malloc(sizeof(node));if(i==j-1)ptr->next=NULL;elseptr=ptr->next;}ptr=head;while(ptr!=NULL){printf("Thevalueis==>%d",ptr->data);ptr=ptr->next;}}=========================================
7、=====================【程序4】题目:反向输出一个链表。 1.程序分析:2.程序源代码:/*reverseoutputalist*/#include"stdlib.h"#includestructlist11{intdata;structlist*next;};typedefstructlistnode;typedefnode*link;voidmain(){linkptr,head,tail;intnum,i;intj;printf("pleaseinputn
此文档下载收益归作者所有