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

  1.    ntrtcx(a,b,n,c,d)
  2.  
  3.       /* subroutine to determine the nth roots of a complex number. */
  4.  
  5.       int n;
  6.       float a,b,c[],d[];
  7.  
  8.     {
  9.       int ak,jn,k,l,p,zn;
  10.       float s,sx,theta,x,z;
  11.       double pi,pi2;
  12.       extern double atan(),cos(),pow(),sin(),sqrt();
  13.  
  14.       p = n;
  15.       s = 0.0;
  16.       pi = 3.141592653589796;
  17.       pi2 = pi * 2;
  18.       if(n < 1)
  19.       {
  20.        c[0] = 0.0;
  21.        d[0] = 0.0;
  22.        return;
  23.       }
  24.       if(n == 1)
  25.       {
  26.        c[0] = a;
  27.        d[0] = b;
  28.        return;
  29.       }
  30.       theta = atan(b/a);
  31.        if(a < 0.) theta = theta + pi;
  32.       theta = theta/p;
  33.       s = sqrt(a*a + b*b);
  34.       x =  1.0/p;
  35.       sx = pow(s,x);
  36.       c[0] = sx * cos(theta);
  37.       d[0] = sx * sin(theta);
  38.       jn = n - 1;
  39.  
  40.       for(k = 1; k <= jn; k++)
  41.       {
  42.       ak = k;
  43.       z = theta + (2.0 * ak * pi)/p;
  44.       zn = z/pi2;
  45.       z = z-(zn*pi2);
  46.       c[k] = sx * cos(z);
  47.       d[k] = sx * sin(z);
  48.       }
  49.     }
  50.