What's Here?
- Members: 149,626
- Replies: 506,753
- Topics: 79,851
- Snippets: 2,666
- Tutorials: 706
- Total Online: 1,984
- Members: 76
- Guests: 1,908
|
This program can divide a polynomial of any degree by a binomial of the type (x-h)
|
Submitted By: Louisda16th
|
|
|
Rating:
|
|
Views: 3,253 |
Language: C++
|
|
Last Modified: September 21, 2006 |
|
Instructions: compile, build and run |
Snippet
//Created by Louisda16th/Ashwith
#include<iostream>
using namespace std;
int main()
{
float *coeff, *anscoeff, k; //coeff contains the coefficients of the dividend and anscoeff contains
int n,i; //coefficient of the answer. n is the degree of the polynomial, i is a counter
cout<<"Enter Degree Of Expression";
cin>>n;
coeff = new float[n];
anscoeff = new float[n-1];
i=n;
//this loop gets the coefficients of the polynomial
while (i>=0)
{
if (i!=0)
{
if (i == 1)
{
cout<<endl<<"Coefficient of x";
cin>>coeff[i];
}
else
{
cout<<endl<<"Coefficient of x^"<<i;
cin>>coeff[i];
}
}
else
{
cout<<endl<<"Enter Constant Term";
cin>>coeff[i];
}
i--;
}
anscoeff[n] = coeff[n];
cout<<endl<<"Enter Constant term(k) of Divisor (x-k)";
cin>>k;
cout<<"Quotient= "<<anscoeff[n]<<"x^"<<n-1;
i=(n-1);
//this loop calculates the coefficients of the quotient and stores them in anscoeff
while (i>0)
{
anscoeff[i]=coeff[i]+k*anscoeff[i+1];
if((i-1)!=0 && (i-1)!=1)
{
if (anscoeff[i]>=0)
cout<<" +"<<anscoeff[i]<<"x^"<<(i-1);
else
cout<<" "<<anscoeff[i]<<"x^"<<(i-1);
}
else if((i-1)==1)
{
if (anscoeff[i]>=0)
cout<<" +"<<anscoeff[i]<<"x";
else
cout<<" "<<anscoeff[i]<<"x";
}
else if((i-1)==0)
{
if (anscoeff[i]>=0)
cout<<" +"<<anscoeff[i];
else
cout<<" "<<anscoeff[i];
}
i--;
}
cout<<endl<<"Remainder= "<<(coeff[0]+k*anscoeff[1]);
cout<<endl;
return 0;
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|