Aim
To write a C++ Program to add subtract multiply divide complex numbers using structure .
Program
#include<iostream>
using namespace std;
main()
{
float a1,a2,d1,d2;
struct complex
{
float a,b;
};
complex c1,c2;
cout<<"Enter the real and imaginary part of 2 the complex number";
cin>>c1.a>>c1.b>>c2.a>>c2.b;
cout<<"The Entered complex number is ";
cout<<c1.a<<"+i"<<c1.b<<"\n"<<c2.a<<"+i"<<c2.b;
cout<<"\n The sum is\n";
a1=c1.a+c2.a;
a2=c1.b+c2.b;
cout<<a1<<"+i"<<a2<<"\n";
cout<<"The difference is "<<c1.a-c2.a<<"+"<<c1.b-c2.b<<"i\n";
cout<<"The product is "<<c1.a*c2.a-c1.b*c2.b<<"+"<<c1.a*c2.a+c1.b*c2.b;
cout<<"i\n";
cout<<"The quotient is ";
d1=((c1.a*c2.a)+(c1.b*c2.b))/((c2.a*c2.a)+(c2.b*c2.b));
d2=((c2.b*c1.a)-(c1.b*c2.a))/((c2.a*c2.a)+(c2.b*c2.b));
cout<<d1<<"+"<<d2<<"i";
return 0;
}
Tags: c++ program to solve complex numbers , c++ program to add complex numbers,c++ program to subtract complex numbers , c++ program to divide complex numbers,c++ program to multiply complex numbers ,algorithm , flowchart
To write a C++ Program to add subtract multiply divide complex numbers using structure .
Program
#include<iostream>
using namespace std;
main()
{
float a1,a2,d1,d2;
struct complex
{
float a,b;
};
complex c1,c2;
cout<<"Enter the real and imaginary part of 2 the complex number";
cin>>c1.a>>c1.b>>c2.a>>c2.b;
cout<<"The Entered complex number is ";
cout<<c1.a<<"+i"<<c1.b<<"\n"<<c2.a<<"+i"<<c2.b;
cout<<"\n The sum is\n";
a1=c1.a+c2.a;
a2=c1.b+c2.b;
cout<<a1<<"+i"<<a2<<"\n";
cout<<"The difference is "<<c1.a-c2.a<<"+"<<c1.b-c2.b<<"i\n";
cout<<"The product is "<<c1.a*c2.a-c1.b*c2.b<<"+"<<c1.a*c2.a+c1.b*c2.b;
cout<<"i\n";
cout<<"The quotient is ";
d1=((c1.a*c2.a)+(c1.b*c2.b))/((c2.a*c2.a)+(c2.b*c2.b));
d2=((c2.b*c1.a)-(c1.b*c2.a))/((c2.a*c2.a)+(c2.b*c2.b));
cout<<d1<<"+"<<d2<<"i";
return 0;
}
Tags: c++ program to solve complex numbers , c++ program to add complex numbers,c++ program to subtract complex numbers , c++ program to divide complex numbers,c++ program to multiply complex numbers ,algorithm , flowchart
No comments:
Post a Comment