We represent polynomials by the linked list and perform addition.
void add(struct node *a,struct node *b,struct node **s)
{
struct node *temp;
if(a==NULL&&b==NULL)
return;
while(a!=NULL&&b!=NULL)
{
if(*s==NULL)
{
*s=malloc(sizeof(struct node));
temp=*s;
}
else
{
temp->link=malloc(sizeof(struct node));
temp=temp->link;
}
if(a->exp<b->exp)
{
temp->coeff=b->coeff;
temp->exp=b->exp;
b=b->link;
}
else if(a->exp>b->exp)
{
temp->coeff=a->coeff;
temp->exp=a->exp;
a=a->link;
}
else if(a->exp==b->exp)
{
temp->coeff=a->coeff+b->coeff;
temp->exp=a->exp;
a=a->link;
b=b->link;
}
}
}