Saturday 18 November 2017

C++ program to add, subtract, multiply and divide two complex numbers using structures


Code:

#include     iostream.h
#include     conio.h
#include     math.h

struct complex
{
float rel;
float img;
}s1,s2;

void main()
{
clrscr();
float a,b;
cout<<“Enter real and imaginary part of 1st complex number:”;
cin>>s1.rel>>s1.img;
cout<<“Enter real and imaginary part of 2nd complex number:”;
cin>>s2.rel>>s2.img;

//Addition
a=(s1.rel)+(s2.rel);
b=(s1.img)+(s2.img);
cout<<“nAddition: “<<“(“<

//Subtraction
a=(s1.rel)-(s2.rel);
b=(s1.img)-(s2.img);
cout<<“nSubtraction: “<<“(“<

//Multiplication
a=((s1.rel)*(s2.rel))-((s1.img)*(s2.img));
b=((s1.rel)*(s2.img))+((s2.rel)*(s1.img));
cout<<“nMultiplication: “<<“(“<

//Division
a=(((s1.rel)*(s2.rel))+((s1.img)*(s2.img)))/(pow(s2.rel,2)+pow(s2.img,2));
b=(((s2.rel)*(s1.img))-((s1.rel)*(s2.img)))/(pow(s2.rel,2)+pow(s2.img,2));
cout<<“nDivision: “<<“(“<

getch();
}


Output:

Execute and get the output.


More C++ Programs:
















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...