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.
Program:
#include<stdio.h>
#include<conio.h>

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

                for(i=0;i<=m;i++){
                                printf("\n Coefficient x[%d] = ", m-i);
                                scanf("%d",&poly[i]);
                }

                printf("\n Enter the value of constant in (x-r) : ");
                scanf("%d",&r);
                q[0] = poly[0];
                for(i=1;i<=m;i++){
                                q[i] = (q[i-1]*r)+poly[i];
                }

                printf("\n Coefficients of quotient are: \n");
                for(i=0;i<m;i++){
                                printf("\t%d",q[i]);
                }
                printf("\n Remainder is: %d", q[m]);
getch();

}

Sample Output:

SYNTHETIC DIVISION
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.