home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / PLYCFC.C < prev    next >
Encoding:
Text File  |  1984-08-30  |  950 b   |  39 lines

  1.    plycfc(p,s,ndp,nds,c,ndc)
  2.  
  3.       /*this function finds the greatest common divisor of two */
  4.       /*polynomials of the form:                               */
  5.       /*a(1)x**nda + a(2)x**(nda-1) + ... + a(nda)x + a(nda+1) */
  6.       /*by a series of divisions until a remainder of zero is found */
  7.  
  8.       int ndp,nds,*ndc;
  9.       float p[],s[],c[];
  10.  
  11.     {
  12.       int ijk,m,n,ndq,ndcc;
  13.       float q[1];
  14.       float xx;
  15.       extern double fabs();
  16.  
  17.    /* while(fabs(xx) <= 0.000005 && ndcc == 0)  */
  18.  
  19.       n = ndp;
  20. l2:   q[0] = 999999.;
  21.       plydiv(p,s,ndp,nds,q,c,ndq,&ndcc);
  22.  
  23.       xx = c[0] / s[0];
  24.       if (fabs(xx) <= 0.000005 && ndcc == 0) goto l21;
  25.       ndp = nds;
  26.       nds = ndcc;
  27.       for(m = 0; m <= ndp; m++)
  28.         p[m] = s[m];
  29.  
  30.       for(n = 0; n <= nds; n++)
  31.         s[n] = c[n];
  32.  
  33.       goto l2;
  34. l21:  ndcc = nds;
  35.       for(n = 0; n <= ndcc; n++)
  36.         c[n] = s[n];
  37.       *ndc = ndcc;
  38.    }
  39.