## 3 Replies - 2344 Views - Last Post: 16 April 2012 - 08:41 AM

### #1 Louisda16th Reputation: 15
• Posts: 1,967
• Joined: 03-August 06

# Synthetic Division

Posted 20 September 2006 - 09:59 PM

Description: compile, build and runThis program can divide a polynomial of any degree by a binomial of the type (x-h)
```//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+k*anscoeff);
cout<<endl;
return 0;

}
```

Is This A Good Question/Topic? 0

## Replies To: Synthetic Division

### #2 Ryano121 Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

## Re: Synthetic Division

Posted 13 February 2011 - 12:14 PM

i tried to divide 1*x^2 + 7*x + 12 by x+4 and it didn't work. Does this really work or am i putting the equation in wrong?

### #3 Louisda16th Reputation: 15
• Posts: 1,967
• Joined: 03-August 06

## Re: Synthetic Division

Posted 13 February 2011 - 10:20 PM

Works for me. Here is what I get when I run the program: Enter Degree Of Expression 2 Coefficient of x^2 1 Coefficient of x 7 Enter Constant Term 12 Enter Constant term(k) of Divisor (x-k) -4 Quotient= 1x^1 +3 Remainder= 0

## Re: Synthetic Division

Posted 16 April 2012 - 08:41 AM

//horner's polynomial soln, synthetic division #include #include #include #include using namespace std; int main() { int it, n, i; double *a,*b,*c,x=-1000; cout<<"Enter the degree of the polynomial:"; cin>>n; a=new double [n]; b=new double [n]; c=new double [n]; cout<<"Enter the coefficients of the polynomial"<> a[i]; do { it = 0; c = a; b = a; do { for ( i = 1; i <= n; i++ ) b[i] = a[i] + x*b[i-1]; for ( i = 1; i < n; i++ ) c[i] = b[i] + x*c[i-1]; x = x - b[n]/c[n-1]; it++; } while (abs( b[n]) > 1e-5 && it<100 ); cout << "The root is:" << x << endl; n--; for ( i = 0; i <= n; i++ ) a[i] = b[i]; } while( n >= 1 ); getch(); return 0; } but my code can't calculate complex roots, please help boys!!!

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }