Polynomial Addition
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<alloc.h>
void CreatePolyFirst();
void CreatePolySecond(); //Function Protypes
void AddPoly();
void Attach(int, int, struct node *);
struct node
{
int coef , exp; //Structure Definition
struct node *next;
} *first=NULL, *second=NULL, *New=NULL, *temp1=NULL,
*temp2=NULL, *result=NULL, *temp3=NULL;
Polynomial Addition
void main()
{
int ch;
clrscr();
do
{
printf("\n***MENU***");
printf("\n1.Create 1st Polynomial”);
printf(“\n2.Create 2nd Polynomial”);
printf("\n3.Add Both Polynomial
printf(”\n4.Exit");
printf("\nPlease Enter the Choice...");
scanf("%d",&ch);
Polynomial Addition
switch(ch)
{
case 1: CreatePolyFirst();
break;
case 2: CreatePolySecond();
break;
case 3: AddPoly();
break;
case 4: exit(0);
default: printf("\n Invalid Choice...");
}
}while(ch!=4);
getch();
}
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New
first = NULL
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
\
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef); 5
if(New->coef==0)
break;
New
first = NULL
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New
first = NULL
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New
first = NULL
printf("\nEnter the Exponent...");
scanf("%d",&New->exp); 2
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New
first = NULL
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New, first
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New,first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
New,first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \ \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef); 8
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \ 8 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \ 8 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp); 1
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \ 8 1 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 \ 8 1 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 8 1 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 8 1 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first New
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 8 1 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 \ \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef); 4
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 \ 4 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 \ 4 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp); 0
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 \ 4 0 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 \ 4 0 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
temp1
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New 5 2 8 1 4 0 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New
temp1
5 2 8 1 4 0 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
New
temp1
5 2 8 1 4 0 \
void CreatePolyFirst()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
first
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(first==NULL)
{
first=New;
temp1=New;
}
else
{
temp1->next=New;
temp1=New;
}
if(New->exp==0)
break;
}}
5 2 8 1 4 0 \
void CreatePolySecond()
{
printf("\nEnter Polynomial in Descending Order...\n");
printf("\nFor end enter 0.\n");
while(1)
{
New=(struct node *) malloc (sizeof (struct node));
New->next=NULL;
printf("\nEnter the Coefficient...");
scanf("%d",&New->coef);
if(New->coef==0)
break;
second
printf("\nEnter the Exponent...");
scanf("%d",&New->exp);
if(Second==NULL)
{
second=New;
temp2=New;
}
else
{
temp2->next=New;
temp2=New;
}
if(New->exp==0)
break;
}}
4 4 7 2 2 1 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL) .
{
New=(struct node *) malloc (sizeof (struct node));
first
second
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL) .
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
qNew
New->next=NULL;
if(p->exp==q->exp) 2==4
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
\
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
qNew
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp) 2<4
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
\
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
qNew
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
\
void Attach(int c,int e,struct node *d) .
{ (4, 4, New)
if(result==NULL)
{
result=d;
temp3=New;
temp3->coef=c;
temp3->exp=e;
}
first p second
qNew
else
{
temp3->next=d;
temp3=d;
temp3->coef=c;
temp3->exp=e;
}
}
result= NULL
4 4 7 2 2 1 \
5 2 8 1 4 0 \
\
void Attach(int c,int e,struct node *d) .
{ (4, 4, New)
if(result==NULL)
{
result=d;
temp3=New;
temp3->coef=c;
temp3->exp=e;
}
first p second
qNew result, temp3
else
{
temp3->next=d;
temp3=d;
temp3->coef=c;
temp3->exp=e;
}
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
\
void Attach(int c,int e,struct node *d) .
{ (4, 4, New)
if(result==NULL)
{
result=d;
temp3=New;
temp3->coef=c;
temp3->exp=e;
}
first p second
qNew result, temp3
else
{
temp3->next=d;
temp3=d;
temp3->coef=c;
temp3->exp=e;
}
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
qres,
temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q res, New temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q res, New temp3
New->next=NULL;
if(p->exp==q->exp) 2==2
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q res, New temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef; x= 5+7=12
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first p second
q res, temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first psecond
res, temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
q
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first psecond
res
temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
q
New
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first psecond
res
temp3
New->next=NULL;
if(p->exp==q->exp) 1==1
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
q
New
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first psecond
res
temp3
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef; x=8+2=10
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
q
New
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 \ \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first psecond
res
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
q
temp3
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first
second
res
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
p
q=NULL
temp3
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 \
void AddPoly()
{
struct node *p,*q,*r; int x;
if(first==NULL || second==NULL)
{
printf("\nYour First or Second Polynomial is Invalid...");
return;
}
p=first; q=second;
while(p!=NULL && q!=NULL)
{
New=(struct node *) malloc (sizeof (struct node));
first
second
res
New->next=NULL;
if(p->exp==q->exp)
{
x=p->coef+q->coef;
if(x!=0)
Attach(x,p->exp,New);
p=p->next;
q=q->next;
}
else if(p->exp<q->exp)
{
Attach(q->coef,q->exp,New);
q=q->next;
}
p
q=NULL
temp3
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 \
else
{
Attach(p->coef, p->exp, New);
p=p->next;
}}
while(p!=NULL)
{
Attach(p->coef,p->exp,p);
p=p->next;}
while(q!=NULL)
{
Attach(p->coef,p->exp,q);
q=q->next;}
first
second
res
printf("\nAddition of Both Polynomial...\n");
if(result==NULL)
{
printf("0"); return;
}
while(result!=NULL)
{
printf("%dx^%d",New->coef,New->exp);
if(result->next!=NULL)
printf(" + ");
New=New->next;
}
}
p
q=NULL
temp3
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 \
else
{
Attach(p->coef, p->exp, New);
p=p->next;
}}
while(p!=NULL)
{
Attach(p->coef,p->exp,p);
p=p->next;}
while(q!=NULL)
{
Attach(p->coef,p->exp,q);
q=q->next;}
first
second
res
printf("\nAddition of Both Polynomial...\n");
if(result==NULL)
{
printf("0"); return;
}
while(result!=NULL)
{
printf("%dx^%d",New->coef,New->exp);
if(result->next!=NULL)
printf(" + ");
New=New->next;
}
}
p=NULL
q=NULL
temp3
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 4 0 \
else
{
Attach(p->coef, p->exp, New);
p=p->next;
}}
while(p!=NULL)
{
Attach(p->coef,p->exp,p);
p=p->next;}
while(q!=NULL)
{
Attach(p->coef,p->exp,q);
q=q->next;}
first
second
res
printf("\nAddition of Both Polynomial...\n");
if(result==NULL)
{
printf("0"); return;
}
while(result!=NULL)
{
printf("%dx^%d",New->coef,New->exp);
if(result->next!=NULL)
printf(" + ");
New=New->next;
}
}
p=NULL
q=NULL
4 4 7 2 2 1 \
5 2 8 1 4 0 \
4 4 12 2 10 1 4 0 \
else
{
Attach(p->coef, p->exp, New);
p=p->next;
}}
while(p!=NULL)
{
Attach(p->coef,p->exp,p);
p=p->next;}
while(q!=NULL)
{
Attach(p->coef,p->exp,q);
q=q->next;}
res
res - > 4x^4 + 12x^2 + 10x^1 + 4
printf("\nAddition of Both Polynomial\n");
if(result==NULL)
{
printf("0"); return;
}
while(result!=NULL)
{
printf("%dx^%d",New->coef,New->exp);
if(result->next!=NULL)
printf(" + ");
New=New->next;
}
}
4 4 12 2 10 1 4 0 \