54
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,

Ploynomial addition

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Ploynomial addition

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;

Page 2: Ploynomial addition

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);

Page 3: Ploynomial addition

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();

}

Page 4: Ploynomial addition

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;

}}

\

Page 5: Ploynomial addition

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 \

Page 6: Ploynomial addition

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 \

Page 7: Ploynomial addition

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 \

Page 8: Ploynomial addition

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 \

Page 9: Ploynomial addition

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 \

Page 10: Ploynomial addition

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 \

Page 11: Ploynomial addition

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 \

Page 12: Ploynomial addition

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 \ \

Page 13: Ploynomial addition

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 \

Page 14: Ploynomial addition

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 \

Page 15: Ploynomial addition

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 \

Page 16: Ploynomial addition

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 \

Page 17: Ploynomial addition

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 \

Page 18: Ploynomial addition

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 \

Page 19: Ploynomial addition

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 \

Page 20: Ploynomial addition

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 \ \

Page 21: Ploynomial addition

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 \

Page 22: Ploynomial addition

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 \

Page 23: Ploynomial addition

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 \

Page 24: Ploynomial addition

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 \

Page 25: Ploynomial addition

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 \

Page 26: Ploynomial addition

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 \

Page 27: Ploynomial addition

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 \

Page 28: Ploynomial addition

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 \

Page 29: Ploynomial addition

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 \

Page 30: Ploynomial addition

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 \

Page 31: Ploynomial addition

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 \

Page 32: Ploynomial addition

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 \

Page 33: Ploynomial addition

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 \

\

Page 34: Ploynomial addition

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 \

\

Page 35: Ploynomial addition

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 \

\

Page 36: Ploynomial addition

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 \

\

Page 37: Ploynomial addition

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 \

\

Page 38: Ploynomial addition

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 \

Page 39: Ploynomial addition

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 \

Page 40: Ploynomial addition

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 \ \

Page 41: Ploynomial addition

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 \ \

Page 42: Ploynomial addition

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 \ \

Page 43: Ploynomial addition

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 \

Page 44: Ploynomial addition

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 \

Page 45: Ploynomial addition

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 \ \

Page 46: Ploynomial addition

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 \ \

Page 47: Ploynomial addition

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 \ \

Page 48: Ploynomial addition

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 \

Page 49: Ploynomial addition

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 \

Page 50: Ploynomial addition

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 \

Page 51: Ploynomial addition

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 \

Page 52: Ploynomial addition

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 \

Page 53: Ploynomial addition

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 \

Page 54: Ploynomial addition

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 \