Search:

Submit Article

# Program to addition of two polynomial

Posted By: Easy Tutor     Category: C++ Programming     Views: 16907

## Code for Program to addition of two polynomial in C++ Programming

```//Addition of Two Polynomial

#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

struct poly{
int coeff;
int pow;
poly *next;
};

{
poly *poly1, *poly2, *poly3;
public:
void display();
};

int i,p;
poly *newl=NULL,*end=NULL;
cout<<"Enter highest power for x\n";
cin>>p;
cout<<"\nFirst Polynomial\n";
for(i=p;i>=0;i--)
{
newl=new poly;
newl->pow=p;
cout<<"Enter Co-efficient for degree"<<i<<"::  ";
cin>>newl->coeff;
newl->next=NULL;
if(poly1==NULL)
poly1=newl;
else
end->next=newl;
end=newl;
}

cout<<"\n\nSecond Polynomial\n";
end=NULL;
for(i=p;i>=0;i--)
{
newl=new poly;
newl->pow=p;
cout<<"Enter Co-efficient for degree"<<i<<"::  ";
cin>>newl->coeff;
newl->next=NULL;
if(poly2==NULL)
poly2=newl;
else
end->next=newl;
end=newl;
}

poly *p1=poly1,*p2=poly2;
end=NULL;
while(p1 !=NULL && p2!=NULL){
if(p1->pow == p2->pow){
newl=new poly;
newl->pow=p--;
newl->coeff=p1->coeff + p2->coeff;
newl->next=NULL;
if(poly3==NULL)
poly3=newl;
else
end->next=newl;
end=newl;
}
p1=p1->next;
p2=p2->next;
}
}

poly *t=poly3;
while(t!=NULL){
cout.setf(ios::showpos);
cout<<t->coeff;
cout.unsetf(ios::showpos);
cout<<"X"<<t->pow;
t=t->next;
}
}

void main(){
clrscr();
obj.display();
getch();
}```
Share:

Didn't find what you were looking for? Find more on Program to addition of two polynomial Or get search suggestion and latest updates.

 Easy Tutor author of Program to addition of two polynomial is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles

• Comment should be atleast 30 Characters.

 Monica Kala from United States Comment on: Oct 10 plz..suggest a code for polynomial subtraction in c(Data structures)