Skip to content

Commit

Permalink
Merge pull request #208 from yashingle/patch-2
Browse files Browse the repository at this point in the history
Create add-complex-numbers.cpp
  • Loading branch information
fineanmol authored Oct 1, 2021
2 parents 6bbb815 + 81059e4 commit 2be66b8
Showing 1 changed file with 40 additions and 0 deletions.
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;
}

0 comments on commit 2be66b8

Please sign in to comment.