# Write a function to add, subtract, multiply, and divide two complex numbers (x +iy) and (c + id). in C

typedef struct {

double real;

double imaginary;

} Complex;

Complex addComplex(Complex a, Complex b) {

Complex result;

result.real = a.real + b.real;

result.imaginary = a.imaginary + b.imaginary;

return result;

}

Complex subtractComplex(Complex a, Complex b) {

Complex result;

result.real = a.real – b.real;

result.imaginary = a.imaginary – b.imaginary;

return result;

}

Complex multiplyComplex(Complex a, Complex b) {

Complex result;

result.real = (a.real * b.real) – (a.imaginary * b.imaginary);

result.imaginary = (a.real * b.imaginary) + (a.imaginary * b.real);

return result;

}

Complex divideComplex(Complex a, Complex b) {

Complex result;

double denominator = (b.real * b.real) + (b.imaginary * b.imaginary);

result.real = ((a.real * b.real) + (a.imaginary * b.imaginary)) / denominator;

result.imaginary = ((a.imaginary * b.real) – (a.real * b.imaginary)) / denominator;

return result;

}

void printComplex(Complex num) {

printf(“%.2f + %.2fi\n”, num.real, num.imaginary);

}

int main() {

Complex x = {3.0, 4.0};

Complex y = {2.0, -1.0};

Complex c = {1.5, 2.5};

Complex d = {0.5, -1.5};

```
Complex addition = addComplex(x, y);
Complex subtraction = subtractComplex(x, y);
Complex multiplication = multiplyComplex(x, y);
Complex division = divideComplex(c, d);
printf("Addition: ");
printComplex(addition);
printf("Subtraction: ");
printComplex(subtraction);
printf("Multiplication: ");
printComplex(multiplication);
printf("Division: ");
printComplex(division);
return 0;
```

}