Sunday, 17 March 2013

C Program for Synthetic Division with algorithm and example

Algorithm of Synthetic Division:
Given a polynomial of form p(x) = anxn + an-1xn-1+…+ a1x+ a0, we can divide it by a linear factor x-r, where ‘r’ is a constant, using following steps.
a.       Write the r on the left side of a vertical bar and the coefficients in decreasing degree.
r| an               an-1         …….        a1            a0
b.      Pass the coefficient of the highest degree below the horizontal line as it is
 r| an              an-1         …….        a1            a0
  |.                                                                   .
  | an             

c.       Multiply the passed coefficient with ‘r’ and add to the next  coefficient
 r| an              an-1         …….        a1            a0
  |.                 an                                                  .
  | an          an-1+ an
d.      Continue the step ‘c’ until all coefficients are covered.

e.      The numbers below an ……. a1 give the coefficients of the quotient whose degree is 1 less than the polynomial, the number below a0 is the remainder.

Example of Synthetic Division:  x2 + 5x+ 6 by x – 1
Writing the coefficients of the polynomial and dividing by the linear factor.
1|1         5              6
  |           1              6
  |1         6              12

Therefore, the quotient Q(x) = x + 6 and remainder R(x) = 12.

void main(){
                int poly[6], m, r, i, q[6];
                printf("\t\tSYNTHETIC DIVISION");
                printf("\n Enter the highest degree of the equation (max 5): ");

                                printf("\n Coefficient x[%d] = ", m-i);

                printf("\n Enter the value of constant in (x-r) : ");
                q[0] = poly[0];
                                q[i] = (q[i-1]*r)+poly[i];

                printf("\n Coefficients of quotient are: \n");
                printf("\n Remainder is: %d", q[m]);


Sample Output:

Enter the highest degree of the equation (max 5): 2

Coefficient x[0] = 1

Coefficient x[1] = 5

Coefficient x[2] = 6

Enter the value of constant in (x—r) : 1

Coefficients of quotient are:
1        6
Remainder is: 12

©Dixit Bhatta 2013

1 comment:

Was this post helpful? Ask any questions you have, I will try to answer them for you.

Follow by Email