Chapter 16
Answers to Selected Exercises 2. [was #2; modified]
(a)
struct {
double real, imaginary;
} c1, c2, c3;
(b)
struct {
double real, imaginary;
} c1 = {0.0, 1.0}, c2 = {1.0, 0.0}, c3;
(c) Only one statement is necessary:
c1 = c2;
(d)
c3.real = c1.real + c2.real;
c3.imaginary = c1.imaginary + c2.imaginary;
4. [was #4; modified]
(a)
typedef struct {
double real, imaginary;
} Complex;
(b) Complex c1, c2, c3;
(c)
Complex make_complex(double real, double imaginary)
{
Complex c;
c.real = real;
c.imaginary = imaginary;