




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
习题8参考答案一、单项选择题DCCDA DDDDB二、填空题 若干个数据项 结构体成员 定义结构体数据类型的变量 同时存在 同时 需要存储区域最大的一个分配存储空间 long * char * double *三、阅读程序题1. 110,z2 ascalbasicb3 5,34 5160215li ming 196abcdefghijk四、程序设计题/xt080401.cpp#include struct compdouble re;double im;typedef struct comp COMP;void main()COMP sub(COMP x,COMP y);COMP a,b,res;printf(Input complex num a:);scanf(%lf,%f,&a.re,&a.im);printf(Input complex num b:);scanf(%lf,%f,&b.re,&b.im);res=sub(a,b);printf(res.re=%g,res.im=%gn,res.re,res.im);COMP sub(COMP x,COMP y)COMP t;t.re=x.re-y.re;t.im=x.im-y.im;return t;/xt080402.cpp#include #include void main()struct node int x;struct node *next;int n;struct node *h=NULL,*p,*q;printf(Input a number: );scanf(%d,&n);while(n)p=(struct node *)malloc(sizeof(struct node);p-x=n;p-next=h;if(!h)h=p;else if(nx)p-next=h;h=p;elseq=h;while(q-next&nq-next-x)q=q-next;p-next=q-next;q-next=p;printf(Input a number: );scanf(%d,&n);p=h;n=0;while(p)printf(%8d,p-x);if(+n%6=0)printf(n);p=p-next;printf(n);/xt080403.cpp#include #include #define N 3struct studchar id5;char name20;int score4;double ave;void inputscore(struct stud *rec);void printscore(struct stud *s);void sum_ave(struct stud *s);void main()struct stud stN;int i;for(i=0;iid);gets(rec-name);for(i=0;iscorei=atoi(in_buf);void sum_ave(struct stud *s)int k,i,sum;for(k=0;kN;k+) sum=0;for(i=0;i4;i+)sum+=sk.scorei;sk.ave=sum/4;void printscore(struct stud *s)int i,k;for(k=0;kN;k+)printf(%st%s:,sk.id,);for(i=0;i4;i+)printf(%5d,sk.scorei);printf(t%fn,sk.ave);/xt080404.cpp#include #include #define N 10void main()void reverse(int v,int n);int arrN,i;printf(Input the element of array:n);for(i=0;iN;i+)scanf(%d,&arri);reverse(arr,N);for(i=0;iN;i+)printf(%5d,arri);printf(n);void reverse(int v,int n)struct nodeint x;struct node *next;struct node *h=NULL,*p;int i;for(i=0;ix=vi;p-next=h;h=p;p=h;for(i=0;p;i+,p=p-next)vi=p-x;/xt080405.cpp#include #define N 3struct stulong id;double shu,yu,ave;void main()struct stu sN;void sort(struct stu v,int n);struct stu *p;for(p=s;pid),&(p-shu),&(p-yu);p-ave=(p-shu+p-yu)/2;sort(s,N);for(p=s;pid,p-shu,p-yu,p-ave);void sort(struct stu v,int n)int i,j,k;struct stu t;for(i=0;in-1;i+)k=i;for(j=i+1;j(*(v+k).ave)k=j;if(k!=i)t=*(v+i),*(v+i)=*(v+k),*(v+k)=t;/xt080406.cpp#include #include struct listint d;struct list *link;typedef struct list L;void main()L *createlist();void printlist(L *h);L *head;head=createlist();printlist(head);L *createlist()L *p,*q,*ph;int a;ph=(L *)malloc(sizeof(L);p=q=ph;printf(Input the element of list,-1 for end.n);scanf(%d,&a);while(a!=-1)p=(L *)malloc(sizeof(L);p-d=a;q-link=p;q=p;scanf(%d,&a);p-link=NULL;return ph;void printlist(L *h)L *p=h-link;while(p!=NULL)printf(%5d,p-d);p=p-link;printf(n);/xt080407.cpp#include #include struct listint d;struct list *link;typedef struct list L;void main()L *createlist();void printlist(L *h);void insert(L *h,int a,int key);int a,k;L *head;head=createlist();printf(Input value for Insert.n);scanf(%d,%d,&a,&k);insert(head,a,k);printlist(head);L *createlist()L *p,*q,*ph;int a;ph=(L *)malloc(sizeof(L);p=q=ph;printf(Input the element of list,-1 for end.n);scanf(%d,&a);while(a!=-1)p=(L *)malloc(sizeof(L);p-d=a;q-link=p;q=p;scanf(%d,&a);p-link=NULL;return ph;void printlist(L *h)L *p=h-link;while(p!=NULL)printf(%5d,p-d);p=p-link;printf(n);void insert(L *h,int a,int key)L *s,*p,*q;s=(L *)malloc(sizeof(L);s-d=key;q=h;p=h-link;if(p=NULL)s-link=p;q-link=s;return;while(p-d!=a&p-link!=NULL)q=p;p=p-link;if(p-d=a)s-link=p;q-link=s;elses-link=NULL;p-link=s;/xt080408.cpp#include #include struct listint d;struct list *link;typedef struct list L;void main()L *createlist();void printlist(L *h);void insert(L *h,int a,int key);void reverselist(L *h);int a,k;L *head;head=createlist();printf(Input value for Insert.n);scanf(%d,%d,&a,&k);insert(head,a,k);printlist(head);reverselist(head);printlist(head);L *createlist()L *p,*q,*ph;int a;ph=(L *)malloc(sizeof(L);p=q=ph;printf(Input the element of list,-1 for end.n);scanf(%d,&a);while(a!=-1)p=(L *)malloc(sizeof(L);p-d=a;q-link=p;q=p;scanf(%d,&a);p-link=NULL;return ph;void printlist(L *h)L *p=h-link;while(p!=NULL)printf(%5d,p-d);p=p-link;printf(n);void insert(L *h,int a,int key)L *s,*p,*q;s=(L *)malloc(sizeof(L);s-d=key;q=h;p=h-link;if(p=NULL)s-link=p;q-link=s;return;while(p-d!=a&p-link!=NULL)q=p;p=p-link;if(p-d=a)s-link=p;q-link=s;elses-link=NULL;p-link=s;void reverselist(L *h)L *p,*q;p=h-link;if(p!=NULL)h-link=NULL;doq=p-link;p-link=h-link;h-link=p;p=q;while(p!=NULL);/xt080409.cpp#include #include typedef struct nodeint no;struct node *next;NODE;void main()int n,start,end,i,count;NODE *h,*p,*tail,*newh;printf(Input the number of people: );scanf(%d,&n);if(n=0!n);return;printf(Input the starting point and ending point:);scanf(%d,%d,&start,&end);if(start1|endno=n;for(i=n-1;i=1;i-)p=(NODE *)malloc(sizeof(NODE);p-no=i;p-next=h;h=p;tail-next=h;h=tail;start=(start-1)%n;for(i=0;inext;for(count=n;count1;count-)start=(end-1)%count;for(i=0;inext;if(newh)tail-next=h-next;tail=h-next;elsenewh=h-next;tail=newh;h-next=h-next-next;tail-next=h;tail=h;tail-next=NULL;count=0;if(n=1)newh=tail;while(newh)printf(%5d,newh-no);newh=newh-next;if(+count%6=0)printf(n);printf(n);/xt080410.cpp#include #include typedef struct nodefloat coef;int exp;struct node *next;NODE;void main()NODE *pa,*pb,*pc,*tail,*p,*q,*r;float coef;int exp,count;pa=(NODE *)malloc(sizeof(NODE);pa-coef=0.0;pa-exp=-1;/*建立多项式A的头节点*/tail=pa;doprintf(输入多项式A中每一项的系数和指数(指数小于0时结束):);scanf(%f,%d,&coef,&exp);if(expcoef=coef;p-exp=exp;tail-next=p;tail=p;while(1);tail-next=NULL;pb=(NODE *)malloc(sizeof(NODE);pb-coef=0.0;pb-exp=-1;/*建立多项式B的头节点*/tail=pb;doprintf(输入多项式B中每一项的系数和指数(指数小于0时结束):);scanf(%f,%d,&coef,&exp);if(expcoef=coef;p-exp=exp;tail-next=p;tail=p;while(1);tail-next=NU
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中考试题及答案绍兴
- 烯烃炔烃试题及答案
- 能源概论试题及答案
- 生活药学考试题及答案
- 中交安全考试试题及答案
- 2025年国家电投集团福建核电招聘考试笔试试题(含答案)
- 北京知识型直播培训课件
- 2025年甘肃烟草公司招聘考试笔试试题(含答案)
- 2025年恩施州鹤峰县县直教育单位选调教师考试笔试试题(含答案)
- 2024年云南省社区《网格员》考前冲刺训练(含答案)
- 慢性疾病管理与健康指导手册
- 2025年高中音乐教师招聘考试测试题及参考答案
- 主持人基础知识培训课件
- 2025年储能运维面试题及答案
- 2025年安徽演艺集团有限责任公司招聘20人笔试备考题库及答案详解(名师系列)
- 2025年事业单位考试医学基础知识真题及答案解析(医疗卫生系统)
- 建筑工地基孔肯雅热防控和应急方案
- 车间现场6S管理课件
- 计量基础知识培训课件
- 2025年新反洗钱知识竞赛题库(附含答案)
- 融媒体中心媒资管理办法
评论
0/150
提交评论