/* * cpx.c - implementation of a simple complex number package * version 1: value parameters & no dynamic allocation * CSE 413 demo 11/06 HP */ #include #include "cpx.h" /* return a complex number with real part = x and imaginary = y */ Complex mk_complex(double x, double y) { Complex result; result.re = x; result.im = y; return result; } /* return the sum of complex numbers c and d */ Complex cpx_add(Complex c, Complex d) { return mk_complex(c.re+d.re, c.im+d.im); } /* store a string represtntation of c as re+im i in s */ void cpx2str(Complex c, char s[]) { sprintf(s, "%g+%gi", c.re, c.im); }