Complex Numbers
Implement a new type Complex
that stores the real
number and the imaginary unit (imag
). Both real
and image
should be double
.
Implement the following
functions:
Complex add(Complex a, Complex b);
Complex sub(Complex a, Complex b);
Complex mul(Complex a, Complex b);
Having these functions in place, it becomes possible to add, substract,
and multiply two complex numbers. The mathematical basis for the
implementation is available for addition and
multiplication.
Use these functions in main(.)
to make sure they produce
the correct outcomes for the following combinations:
- 5+5i, 7+i (results:
add -> 12.0+6.0i, sub -> -2.0+4.0i, mul -> 30.0+40.0i
)
- 5+5i, 7-3i (results:
add -> 12.0+2.0i, sub -> -2.0+8.0i, mul -> 50.0+20.0i
)
- 3-2i, 7-3i (results:
add -> 10+-5i, sub -> -4+1i, mul -> 15-23i
)
- -5, 7-3i (results:
add -> 2-3i, sub -> -12+3i, mul -> -35+15i
)
Name the source file: complex_numbers.c