Translate

Wednesday, 29 August 2012

//Addition of two POLYNOMIAL's

#include<iostream.h>
#include<conio.h>
void main()
{
    int co[10],i,p,k,co2[10],co1[10];
    char po[9];
    clrscr();
    for(i=0;i<10;i++)
    {
        co[i]=0;
    }
    cout<<"\nPlease enter the power of the polynomial\ni.e. the highiest power"<<endl;
    cin>>p;
    cout<<"\nPlease enter the polynomial \nAs:2 x*x+ 3 x+ 7\n"<<endl;
    for(i=0;i<p+1;i++)
    {
        cin>>co[i];
        if(i!=p)
        cin>>po;
    }
    for(i=0;i<p+1;i++)
    {
        cout<<co[i];
        for(k=0;k<p-i;k++)
        {
            cout<<"x";
            if(k!=(p-(i+1)))
            cout<<"*";
        }
        if(i!=p)
        cout<<"+";
    }
    cout<<"\nPlease enter the power of the polynomial\ni.e. the highiest power"<<endl;
    cin>>p;
    cout<<"\nPlease enter the polynomial \nAs:2 x*x+ 3 x+ 7\n"<<endl;
    for(i=0;i<p+1;i++)
    {
        cin>>co2[i];
        if(i!=p)
        cin>>po;
    }
    for(i=0;i<p+1;i++)
    {
        cout<<co2[i];
        for(k=0;k<p-i;k++)
        {
            cout<<"x";
            if(k!=(p-(i+1)))
            cout<<"*";
        }
        if(i!=p)
        cout<<"+";
    }
         cout<<endl;
    for(i=0;i<=p;i++)
    {
        co1[i]=co2[i]+co[i];
    }
    cout<<"\nThe addition of polynomial is:....."<<endl;
     for(i=0;i<p+1;i++)
    {
        cout<<co1[i];
        for(k=0;k<p-i;k++)
        {
            cout<<"x";
            if(k!=(p-(i+1)))
            cout<<"*";
        }
        if(i!=p)
        cout<<"+";
    }
    getch();
}

No comments:

Post a Comment