Answer:
#include <iostream>
using namespace std;
struct complex{//structure of comlex number..
double real;
double img;
};
complex add_complex(complex n1,complex n2)//add_complex functrion to add 2 complex numbers..
{
double a,b;//variables to hold the sum of real and imaginary.
complex sum;//result sum complex number.
a=n1.real+n2.real;//adding real parts.
b=n1.img+n2.img;//adding imaginary parts..
sum.real=a;//assinging values to sum.
sum.img=b;
return sum;//returning complex number sum.
}
int main()
{
complex c1,c2,sum;
double a,b;
cout<<"Enter values of c1"<<endl;
cin>>a>>b;
c1.real=a;
c1.img=b;
cout<<"Enter values of c2"<<endl;
cin>>a>>b;
c2.real=a;
c2.img=b;
sum=add_complex(c1,c2);
cout<<"The sum is : "<<sum.real<<" + i"<<sum.img<<endl;
return 0;
}
OUTPUT:-
Enter values of c1
8.5 7.2
Enter values of c2
4.5 3.9
The sum is : 13 + i11.1
Step-by-step explanation:
First I have created a structure for complex number.Then created a function to add two complex numbers according to the question which returns a complex number.