C语言多项式加减.c

多项式加减:用单链表表示多项式,并进行多项式加减运算

1.结点结构:

typedef struct linkednode
{
    int coef;
    int exp;
    struct linkednode *next;    
}snode,*ptr;

coef是系数,exp是指数,next是值域。

snode是结点类型名,ptr是结点指针类型名。

2.链表创建:

ptr creatlinked_B()
{
    ptr head,last,p;
    int x,y;
    head=last=(ptr)malloc(sizeof(snode));
    last->next=NULL;
    printf("输入系数:\n"); 
    scanf("%d",&x);
    printf("输入指数:\n"); 
    scanf("%d",&y);
    printf("\n");
    while(x!=0 && y!=0)    
    {
        p=(ptr)malloc(sizeof(snode));
        p->coef=x;
        p->exp=y;
        last->next=p;
        p->next=NULL;
        last=p;
        printf("输入系数:\n"); 
        scanf("%d",&x);
        printf("输入指数:\n"); 
        scanf("%d",&y);
        printf("\n");
    }
    p=head;
    head=head->next;
    free(p);
    return head;    
}

3.链表输出:

void outlinkA(ptr p)
{
    printf("多项式为:\n");
    while(p!=NULL)
    {
        if(p->coef>0)
        {
            printf("+");
            printf("%d",p->coef);
        }
            
        if(p->coef<0)
            printf("%d",p->co
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超级无敌暴龙战士xin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值