Tuesday, October 11, 2016

Addition Of Polynomials Using Array :)

Tags


#include<iostream>
using namespace std;
main()
{
int a[100],b[100],c[100],n,m,e;
cout<<"Enter the Max Power of Polynomial ";
cin>>n;
n++;
cout<<"Enter The Max power Of 2nd Polynomial ";
cin>>m;
m++;
cout<<"Enter the Coefficents and Constants\n";
for(int i=0;i<n;i++)
cin>>a[i];
cout<<"Enter The Coefficents and Constants\n";
for(int i=0;i<m;i++)
cin>>b[i];
if(m==n)
{
e=n;
for(int i=0;i<n;i++)
c[i]=a[i]+b[i];}
else if(m<n)
{ e=n;

for(int i=0;i<m;i++)
c[i]=a[i]+b[i];
for(int i=n-1;i>=m;i--)
{
c[i]=a[i];
}
}
else
{e=m;

for(int i=0;i<n;i++)
c[i]=a[i]+b[i];
for(int i=m-1;i>=n;i--)
c[i]=b[i];
}
cout<<"Coefficents and Constants of Result Polynomial  ";
for(int i=0;i<e;i++)
cout<<c[i]<<"x^"<<i<<"+";
}

Output: