c语言多项式运算,多项式的运算(c语言实现).docx

多项式的运算(c语言实现)

#include "stdio.h"#include "stdlib.h"#include "conio.h"

typedef struct Item{ double coef;//系数 int expn;//指数 struct Item *next; }Item,*Polyn;

#define CreateItem(p) p=(Item *)malloc(sizeof(Item));#define DeleteItem(p) free((void *)p);

/************************************************************//* 判断选择函数 *//************************************************************/int Select(char *str) { char ch; printf("%s\n",str); printf("Input Y or N:"); do{ ch=getch();}while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n'); printf("\n"); if(ch=='Y'||ch=='y') return(1); else return(0); }/************************************************************//* 插入位置定位函数 *//**************************************************************/int InsertLocate(Polyn h,int expn,Item **p) { Item *pre,*q; pre=h; q=h->next; while(q&&q->expnnext; } if(!q) { *p=pre; return(1); } else if(q->expn==expn) { *p=q; return(0); } else { *p=pre; return(-1); } }/************************************************************//* 插入结点函数 *//************************************************************/void insert(Item *pre,Item *p){ p->next=pre->next; pre->next=p; }/************************************************************//* 输入多项式 *//************************************************************/Polyn Input(void){ double coef; int expn,flag; Item *h,*p,*q,*pp; CreateItem(h);//产生头结点 h->next=NULL; printf("input coef and expn(if end ,expn=-1)\n"); while(1) { scanf("%lf%d",&coef,&expn); //输入多项式的系数和指数 if(expn==-1) break; //若指数为-,表示输入结束 if(InsertLocate(h,expn,&pp))//返回值非表示插入新结点 { CreateItem(p); p->coef=coef; p->expn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值