多项式求导
编译没问题,但运行不了。。。。#include<stdio.h>
typedef struct node
{
float coef;
int exp;
struct node*next;}Pnode;
Pnode*createht(int tag)
{
float x;int y;
Pnode*p,*r,*h=(Pnode*)malloc(sizeof(Pnode));
r=h;
printf("input x,y:");
scanf("%f%d",&x,&y);
while(y!=tag)
{
p=(Pnode*)malloc(sizeof(Pnode));
p->coef=x;
p->exp=y;
r->next=p;
r=p;
scanf("%f%d",&x,&y);
}
r->next =NULL;
return h;
}
void poly(Pnode*h)
{
Pnode*pre,*p,*q;
pre=h;
p=h->next;
while(p)
{
if(p->exp==0)
{
pre->next =NULL;
free(p);
break;
}
else
{
p->coef =p->coef*p->exp ;
p->exp --;
pre=p->next;
}
}
}
main()
{
int tag=-1;Pnode*h,*p;
h=createht(tag);
poly(h);
p=h->next;
while(p)
{
printf("%f%d\n",p->coef,p->exp);
p=p->next ;
}
}