#include<iostream.h>
#include<conio.h>
struct complex
{
int real;
int img;
};
complex add(complex c1,complex c2)
{
complex temp;
temp.real=c1.real+c2.real;
temp.img=c1.img+c2.img;
return temp;
}
complex sub(complex c1,complex c2)
{
complex temp;
temp.real=c1.real-c2.real;
temp.img=c1.img-c2.img;
return temp;
}
void main()
{
clrscr();
int op;
complex c1,c2,c3,c4;
cout<<"\n";
cout<<"enter real and imaginery part";
cout<<"\n\n";
cin>>c1.real;
cout<<"\n";
cin>>c1.img;
cout<<"\n";
cout<<"enter real and imaginery part";
cout<<"\n\n";
cin>>c2.real;
cout<<"\n";
cin>>c2.img;
cout<<"\n";
cout<<"1. add \n\n2. sub";
cout<<"\n\n";
cout<<"enter your option";
cout<<"\n\n";
cin>>op;
cout<<"\n";
switch(op)
{
case 1:c3=add(c1,c2);
cout<<c3.real<<"+i"<<c3.img;
break;
case 2:c4=sub(c1,c2);
cout<<c4.real<<"+i"<<c4.img;
break;
default:cout<<"invalid option";
break;
}
getch();
}
#include<conio.h>
struct complex
{
int real;
int img;
};
complex add(complex c1,complex c2)
{
complex temp;
temp.real=c1.real+c2.real;
temp.img=c1.img+c2.img;
return temp;
}
complex sub(complex c1,complex c2)
{
complex temp;
temp.real=c1.real-c2.real;
temp.img=c1.img-c2.img;
return temp;
}
void main()
{
clrscr();
int op;
complex c1,c2,c3,c4;
cout<<"\n";
cout<<"enter real and imaginery part";
cout<<"\n\n";
cin>>c1.real;
cout<<"\n";
cin>>c1.img;
cout<<"\n";
cout<<"enter real and imaginery part";
cout<<"\n\n";
cin>>c2.real;
cout<<"\n";
cin>>c2.img;
cout<<"\n";
cout<<"1. add \n\n2. sub";
cout<<"\n\n";
cout<<"enter your option";
cout<<"\n\n";
cin>>op;
cout<<"\n";
switch(op)
{
case 1:c3=add(c1,c2);
cout<<c3.real<<"+i"<<c3.img;
break;
case 2:c4=sub(c1,c2);
cout<<c4.real<<"+i"<<c4.img;
break;
default:cout<<"invalid option";
break;
}
getch();
}