home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / PLYADD.C < prev    next >
Encoding:
Text File  |  1984-06-21  |  849 b   |  44 lines

  1.    plyadd (a,nda,b,ndb,c,ndc)
  2.  
  3.       /*this function performs polynomial addition, c = a + b.*/
  4.  
  5.      int nda,ndb,*ndc;
  6.      float a[],b[],c[];
  7.  
  8.     {
  9.       int n, ndif,ndcp1,i,j,k;
  10.       float x,y;
  11.  
  12.       ndif = abs(nda-ndb);
  13.       n = nda;
  14.       if(nda <  ndb) n = ndb;
  15.       ndcp1 = n + 1;
  16.       j = n ;
  17.  
  18.       for(i = 0; i <= ndcp1-1; i++)
  19.       {
  20.        k = j - ndif;
  21.        x = a[j];
  22.        if(nda < ndb) x = b[j];
  23.        if(j > (ndif-1))
  24.        {
  25.         y = b[k];
  26.         if(nda <  ndb) y = a[k];
  27.         x = x + y;
  28.        }
  29.        c[j] = x;
  30.        j = j - 1;
  31.       }
  32.      *ndc = n;
  33.       for(i = 0; i <= ndcp1-1; i++)
  34.        if(c[i] != 0.0) goto a10;
  35.       *ndc = 0;
  36.       return;
  37. a10:  *ndc = *ndc - i;
  38.       for(j = 0; j <= *ndc; j++)
  39.       {
  40.        c[j] = c[i];
  41.        i = i + 1;
  42.       }
  43.    }
  44.