Assign 4
Assign 4
int coeff;
int exp;
}p;
p p1[10],p2[10],p3[30],p4[30];
int main()
int t1,t2,t3,t4,x;
t1=read(p1);
print(p1,t1);
cout<<endl<<"\nEnter x= ";
cin>>x;
cout<<"\n Evaluated Result = "<<evaluate(x,t1);
t2=read(p2);
print(p2,t2);
t3=add(p1,p2,t1,t2,p3);
cout<<"\n\nAddition of Polynomial:\n";
print(p3,t3);
t4=mult(t1,t2,p1,p2,p4);
print(p4,t4);
cout<<"Enter x= ";
cin>>x;
return 0;
int t1,i;
return (t1);
int t1, i;
for (i=0;i<term-1;i++)
cout <<pp[i].coeff <<"x^" << pp[i].exp<<" " << "+" <<" " ;
cout <<pp[i].coeff <<"x^" << pp[i].exp<<" " << "+" <<" " ;
int i=0,j=0,k=0;
int t3;
if(p1[i].exp==p2[j].exp)
{
p3[k].coeff=p1[i].coeff+p2[j].coeff;
p3[k].exp=p1[i].exp;
i++;j++;k++;
else if(p1[i].exp>p2[j].exp)
p3[k].coeff=p1[i].coeff;
p3[k].exp=p1[i].exp;
i++;k++;
else
p3[k].coeff=p2[j].coeff;
p3[k].exp=p2[j].exp;
j++;k++;
while(i<t1)
p3[k].coeff=p1[i].coeff;
p3[k].exp=p1[i].exp;
i++;k++;
}
while(j<t2)
p3[k].coeff=p2[i].coeff;
p3[k].exp=p2[i].exp;
j++;k++;
t3=k;
return (t3);
int i,j,k,next,found;
int ex;
int co;
i=next=0;
while(i<t1)
j=0;
while(j<t2)
ex=p1[i].exp+p2[j].exp;
co=p1[i].coeff*p2[j].coeff;
k=0;
found=0;
while(k<next && !found)
if(p4[k].exp==ex)
found=1;
else
k++;
if(found)
co=p4[k].coeff+co;
else
p4[next].exp=ex;
p4[next].coeff=co;
next++;
j++;
i++;
return (next);
int sum=0,se=0;
int temp,po=x;
for(int i=0;i<terms;i++)
temp=p1[i].exp;
for(int j=temp;j>1;j--)
po=po*po;
if(temp==0)
sum+=p1[i].coeff;
else
sum+=p1[i].coeff * po;
po=x;
return(sum);