#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: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”;
//Subtraction
a=(s1.rel)-(s2.rel);
b=(s1.img)-(s2.img);
cout<<“nSubtraction: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”;
//Multiplication
a=((s1.rel)*(s2.rel))-((s1.img)*(s2.img));
b=((s1.rel)*(s2.img))+((s2.rel)*(s1.img));
cout<<“nMultiplication: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”;
//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: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”;
getch();
}
1 no bhava
this program is showing eror
mul problem..
//Here is the correct program
#include
#include
using namespace std;
struct complex
{
float rel;
float img;
}s1,s2;
int main()
{
float a,b;
cout<>s1.rel>>s1.img;
cout<>s2.rel>>s2.img;
//Addition
a=(s1.rel)+(s2.rel);
b=(s1.img)+(s2.img);
cout<<"\nAddition: "<<a<<"+"<<b<<"i";
//Subtraction
a=(s1.rel)-(s2.rel);
b=(s1.img)-(s2.img);
cout<<"nSubtraction: "<<a<<"+"<<b<<"i";
//Multiplication
a=((s1.rel)*(s2.rel))-((s1.img)*(s2.img));
b=((s1.rel)*(s2.img))+((s2.rel)*(s1.img));
cout<<"nMultiplication: "<<a<<"+"<<b<<"i";
//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: "<<a<<"+"<<b<<"i";
}
/* —- Here is the correct program —- */
#include
#include
#include
using namespace std;
struct complex
{
float rel;
float img;
}s1,s2;
void main()
{
setlocale(LC_ALL,””);
system(“cls”);
float a,b;
cout<>s1.rel>>s1.img;
cout<>s2.rel>>s2.img;
//Addition
a=(s1.rel)+(s2.rel);
b=(s1.img)+(s2.img);
cout<<"Addition: "<<"("<<a<<")"<<"+"<<"("<<b<<")"<<"i" << endl;
//Subtraction
a=(s1.rel)-(s2.rel);
b=(s1.img)-(s2.img);
cout<<"nSubtraction: "<<"("<<a<<")"<<"+"<<"("<<b<<")"<<"i" << endl;
//Multiplication
a=((s1.rel)*(s2.rel))-((s1.img)*(s2.img));
b=((s1.rel)*(s2.img))+((s2.rel)*(s1.img));
cout<<"Multiplication: "<<"("<<a<<")"<<"+"<<"("<<b<<")"<<"i" << endl;
//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<<"Division: "<<"("<<a<<")"<<"+"<<"("<<b<<")"<<"i" << endl;
cout<<"Enter!";
getch();
}
sir g apka koi youtube chanal ha plz tel me?
Yes. Here is the link for his channel..
https://www.youtube.com/channel/UC3vZ9xaBqLTtLAD-Huwj5Tg
I want this program in java language by using constructors.
Write a program to develop a class Complex with data members as i and j. Accept
two complex numbers, add these two complex numbers and display the result.
Pass object as function argument also return an object.