Question #189103

Expert's answer

```
#include <iostream>
using namespace std;
typedef struct {
double real;
double imaginary;
} Complex;
Complex complexSum(Complex a, Complex b) {
Complex sum;
sum.real = a.real + b.real;
sum.imaginary = a.imaginary + b.imaginary;
return sum;
}
void complexPrint(Complex a) {
if ( a.imaginary > 0 ) {
cout << a.real << "+" << a.imaginary << "i";
}
if ( a.imaginary < 0 ) {
cout << a.real << a.imaginary << "i";
}
if ( a.imaginary == 0 ) {
cout << a.real;
}
}
int main() {
Complex z1, z2, sum;
cout << "Please enter real and imaginary parts for the first complex number:" << "\n";
cin >> z1.real >> z1.imaginary;
cout << "\nPlease enter real and imaginary parts for the second complex number:" << "\n";
cin >> z2.real >> z2.imaginary;
sum = complexSum(z1, z2);
cout << "\nThe sum of your complex numbers is: ";
complexPrint(sum);
return 0;
}
```

Learn more about our help with Assignments: C++

## Comments

## Leave a comment