Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create add-complex-numbers.cpp #208

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* C++ Program to add two Complex Numbers */
#include<iostream>
using namespace std;
class Complex{
public:
int real;
int imag;
/* Function to set the values of
* real and imaginary part of each complex number
*/
void setvalue()
{
cin>>real;
cin>>imag;
}
/* Function to display the sum of two complex numbers */
void display()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
/* Function to add two complex numbers */

void sum(Complex c1, Complex c2)
{
real=c1.real+c2.real;
imag=c1.imag+c2.imag;
}
};
int main()
{
Complex c1,c2,c3;
cout<<"Enter real and imaginary part of first complex number"<<endl;
c1.setvalue();
cout<<"Enter real and imaginary part of second complex number"<<endl;
c2.setvalue();
cout<<"Sum of two complex numbers is"<<endl;
c3.sum(c1,c2);
c3.display();
return 0;
}