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

  1.    cxarth(a,b,c,n)
  2.  
  3.       /*this subroutine does complex arithmetic involving
  4.         two complex numbers.
  5.  
  6.           n=1 for addition
  7.           n=2 for subtraction
  8.           n=3 for multiplication
  9.           n=4 for division                                   */
  10.  
  11.       int n;
  12.       float a[],b[],c[];
  13.  
  14.     {
  15.       double g,x,y;
  16.  
  17.       x = b[0];
  18.       y = a[0];
  19.       if(n == 1)
  20.       {
  21.        c[0] = x + y;
  22.        c[1] = a[1] + b[1];
  23.        return;
  24.       }
  25.       if(n == 2)
  26.       {
  27.        c[0] = y - x;
  28.        c[1] = a[1] - b[1];
  29.        return;
  30.       }
  31.       if(n == 3)
  32.       {
  33.        c[0] = y*x - a[1]*b[1];
  34.        c[1] = a[1]*x + y*b[1];
  35.        return;
  36.       }
  37.       if(n == 4)
  38.       {
  39.        g = x*x + b[1]*b[1];
  40.        c[0] = (y*x + a[1]*b[1])/g;
  41.        c[1] = (a[1]*x - y*b[1])/g;
  42.        return;
  43.       }
  44.      c[0] = -99999;
  45.      c[1] = -99999;
  46.     }
  47.  
  48.