home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_01 / 1n01079a < prev    next >
Text File  |  1990-05-17  |  701b  |  42 lines

  1. #include "stdio.h"
  2.  
  3. struct complex
  4.     {
  5.     double real, imag;
  6.     };
  7.      
  8. struct complex cplx_add(struct complex a, struct complex b);
  9. int cplx_print(struct complex c);
  10.      
  11. int main()
  12.     {
  13.     struct complex c1, c2, c3;
  14.  
  15.     c1.real = 1.5;
  16.     c1.imag = 0.0;
  17.  
  18.     c2.real = 7.1;
  19.     c2.imag = 8.0;
  20.  
  21.     c3 = cplx_add(c1,c2);
  22.  
  23.     cplx_print(c3);
  24.  
  25.     return 0;
  26.     }
  27.      
  28. struct complex cplx_add(struct complex a, struct complex b)
  29.     {
  30.     struct complex result;
  31.  
  32.     result.real = a.real + b.real;
  33.     result.imag = a.imag + b.imag;
  34.  
  35.     return result;
  36.     }
  37.  
  38. int cplx_print(struct complex c)
  39.     {
  40.     return printf("(%g%+gi)",c.real,c.imag);
  41.     }
  42.