求多项式的导函数.doc_第1页
求多项式的导函数.doc_第2页
求多项式的导函数.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*求多项式的导函数*/#include #include typedef struct nodetypefloat coef;/*系数域*/int expn;/*指数域*/struct nodetype *next;/*指针域*/ node, *pointer;/*node为结点的类型 pointer为指针的类型*/typedef structpointer head;/*头指针*/pointer tail;/*尾指针*/pointer cursor;/*当前指针*/ listtype;/*线性表的类型*/void initiate(listtype *list)/*初始化,头结点成为当前结点*/pointer p;p=(pointer)malloc(sizeof(node);p-next=NULL;list-head=list-tail=list-cursor=p;void insertlast(listtype *list, float c, int e)/*插入到线性表尾部,新结点成为当前结点*/pointer p;p=(pointer)malloc(sizeof(node);p-coef=c;p-expn=e;p-next=NULL;list-tail-next=p;list-tail=list-cursor=p;int empty(listtype list)/*判空*/return list.head=list.tail;void findfirst(listtype *list)/*找第一个元素,第一个结点成为当前结点*/list-cursor=list-head-next;void findnext(listtype *list, int *success)/*找下一个元素,当前结点的下一个结点成为当前结点*/if (list-cursor-next!=NULL)list-cursor=list-cursor-next;*success=1;else*success=0;void get(listtype list1, float *c, int *e)/*取元素*/*c=list1.cursor-coef;*e=list1.cursor-expn;void compute(listtype *list2, float c, int e)/*求一项的导函数*/if (e != 0)insertlast(list2, c*e, e-1);void write(listtype list)/*打印一项*/if (list.cursor != list.head-next & list.cursor-coef 0)printf(+);printf(%f, list.cursor-coef);if (list.cursor-expn 0)printf(x);if (list.cursor-expn 1)printf(%d, list.cursor-expn);void readpoly(listtype *list1)/*读多项式,每输入一项的系数和指数后换行,最后输入0,0后结束*/float c;int e;initiate(list1);printf(coef,expn=?);scanf(%f,%d,&c,&e);while (c != 0)insertlast(list1,c,e);printf(coef,expn=?);scanf(%f,%d,&c,&e);void computepoly(listtype list1, listtype *list2)/*求多项式的导函数*/float c;int e, success;initiate(list2);if (!empty(list1)findfirst(&list1);doget(list1, &c, &e);compute(list2, c, e);findnext(&list1, &success);while (success);void writepoly(listtype *list2)/*打印多项式*/int success;if (empty(*list2)printf(0n);elsefindfirst(list2);dowrite(*list2);findnext(list2, &success);while (success);printf(n);m

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论