文档详情

一元多项式求导数.doc

发布:2017-04-16约字共4页下载文档
文本预览下载声明
Description 一个一元多项式可以看作由若干个一元单项式按降幂排列成的线性表。请编写程序对输入的一元多项式进行求导,并输出求导的结果。 Input 输入为一个一元多项式,按照降幂依次输入每个单项式的系数和指数,并以-1 -1作为结束。系数和指数均为整数,指数不小于0。 Output 输出为求导结果多项式,按照降幂依次输出每个单项的系数和指数,每个数值后面用一个空格隔开,输出结果多项式后换行。 系数为0的单项式不得输出——除非结果多项式就是0,则直接输出0并换行。 #include stdio.h #include malloc.h typedef struct polynode { int c; int e; struct polynode *next; } poly; poly *creatpoly() { poly *p, *q, *h; q = NULL, h = NULL; int c; int e; while (e!=-1) { scanf(%d%d, c, e); /*将scanf位置改变下*/ h = (poly*)malloc(sizeof(poly)); h-c = c; h-e = e; h-next = NULL; if (q == NULL) q = h; else p-next = h; p = h; } return q; } poly *qiudao(poly *p) { poly *s; s = p; while (p) { p-c = (p-c)*(p-e); p-e = (p-e) - 1; p = p-next; } return s; } void print(poly *p) { int i = 0; if (p-e == - 1) { printf(0); i++; } { while (p-next != NULL) { if (p-c != 0) { printf(%d %d , p-c, p-e); i++; } else ; p = p-next; } if (p-next == NULL) { if (p-c != 0 p-e -1) /*加上约束条件p-e-1*/ { printf(%d %d , p-c, p-e); i++; } else ; } if (i == 0) printf(0); printf(\n); } } int main() { poly *d, *h; d = creatpoly(); h = qiudao(d); print(h); getchar(); getchar(); return 0; }
显示全部
相似文档