C语言元多项式计算

上传人:痛*** 文档编号:147804754 上传时间:2022-09-03 格式:PDF 页数:7 大小:53.76KB
返回 下载 相关 举报
C语言元多项式计算_第1页
第1页 / 共7页
C语言元多项式计算_第2页
第2页 / 共7页
C语言元多项式计算_第3页
第3页 / 共7页
点击查看更多>>
资源描述
#define LEN sizeof(node)/结点构造typedef struct polynodeint coef;/系数指数int exp;/struct polynode*next;node;node*create(void)node*h,*r,*s;int c,e;h=(node*)malloc(LEN);r=h;printf(系数:);scanf(%d,&c);printf(指数:);scanf(%d,&e);while(c!=0)s=(node*)malloc(LEN);s-coef=c;s-exp=e;r-next=s;r=s;printf(系数:);scanf(%d,&c);printf(指数:);scanf(%d,&e);r-next=NULL;return(h);void polyadd(node*polya,node*polyb)node*p,*q,*pre,*temp;int sum;p=polya-next;q=polyb-next;pre=polya;while(p!=NULL&q!=NULL)if(p-expq-exp)pre-next=p;pre=pre-next;p=p-next;else if(p-exp=q-exp)sum=p-coef+q-coef;if(sum!=0)p-coef=sum;pre-next=p;pre=pre-next;p=p-next;temp=q;q=q-next;free(temp);elsetemp=p-next;free(p);p=temp;temp=q-next;free(q);q=temp;elsepre-next=q;pre=pre-next;q=q-next;if(p!=NULL)pre-next=p;elsepre-next=q;void print(node*p)while(p-next!=NULL)p=p-next;printf(”d*xA%d,p-coef,p-exp);void main()node*polya,*polyb;printf(请输入第一个多项式的系数和指数n(输入系数为0时,表示多项式的输入结 束):n);polya=create();printf(多项式为:);print(polya);printf(nn请输入第二个多项式的系数和指数n(输入系数为0时,表示多项式的输 入结束):n);polyb=create();printf(多项式为:);print(polyb);printf(nn多项式和为:);polyadd(polya,polyb);print(polya);printf(n);getchar();
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!