收藏 分销(赏)

c语言实现多项式求导.doc

上传人:快乐****生活 文档编号:4321617 上传时间:2024-09-06 格式:DOC 页数:4 大小:48.79KB
下载 相关 举报
c语言实现多项式求导.doc_第1页
第1页 / 共4页
c语言实现多项式求导.doc_第2页
第2页 / 共4页
c语言实现多项式求导.doc_第3页
第3页 / 共4页
c语言实现多项式求导.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、#include #include/动态申请空间的函数的头文件 typedef struct node /定义节点类型 float coef; /多项式的系数 int expn; /多项式的指数 struct node * next; /结点指针域 PLOYList; void insert(PLOYList *head,PLOYList *input) /查找位置插入新链节的函数,且让输入的多项式呈降序排列 PLOYList *pre,*now; int signal=0; pre=head; if(pre-next=NULL) pre-next=input; /如果只有一个头结点,则把新结

2、点直接连在后面 else now=pre-next;/如果不是只有一个头结点,则设置now指针 while(signal=0) if(input-expn expn) if(now-next=NULL) now-next=input; signal=1; else pre=now; now=pre-next;/始终让新输入的数的指数与最后一个结点中的数的指数比较,小于则插在其后面 else if( input-expn now-expn ) input-next=now; pre-next=input; signal=1; /若新结点中指数比最后一个结点即now中的指数大,则插入now之前 e

3、lse/若指数相等则需合并为一个结点,若相加后指数为0则释放该结点 now-coef=now-coef+input-coef; signal=1; free(input); if(now-coef=0) pre-next=now-next; free(now); /else /while /else /void PLOYList *creat(char ch) /输入多项式 PLOYList *head,*input; float x; int y; head=(PLOYList *)malloc(sizeof(PLOYList); /创建链表头 head-next=NULL; scanf(%

4、fx %d+,&x,&y);/实现用户输入的第一个项,包括其指数和系数 while(x!=0)/当用户没有输入结束标志0时可一直输入多项式的项,且输入一个创建一个结点 input=(PLOYList *)malloc(sizeof(PLOYList); /创建新链节 input-coef=x; input-expn=y; input-next=NULL; insert(head,input); /每输入一项就将其排序,是的链表中多项式呈降序排列 scanf(%fx %d+,&x,&y); return head; PLOYList *der(PLOYList *head)/多项式求导 PLOY

5、List *p; p = head - next; while (p) p - coef = p - coef * p - expn; p - expn = p - expn-; p = p - next; return head; /将多项式的每项系数和指数相乘得到新的系数,指数减一得到新的指数即完成求导 void print(PLOYList *fun) /输出多项式,fun指要输出的多项式链表的表头 PLOYList *printing; int flag=0; printing=fun-next; if(fun-next=NULL)/若为空表,则无需输出 printf(0n); ret

6、urn; while(flag=0) if(printing-coef0&fun-next!=printing) printf(+); if(printing-coef=1); else if(printing-coef=-1) printf(-); else printf(%f,printing-coef); if(printing-expn!=0) printf(x%d,printing-expn); else if(printing-coef=1)|(printing-coef=-1) printf(1); if(printing-next=NULL) flag=1; else printing=printing-next; printf(n); void main() PLOYList *f; printf( 注:输入多项式格式举例:3x3+3x 并以0 0 结束:n); printf(请输入一个一元多项式:); f = creat(f); printf(这个多项式为:f(x)= ); print(f); printf(求导结果为:F(x)=f(x)= ); f=der(f); print(f); printf(nn);

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服