-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from yashingle/patch-2
Create add-complex-numbers.cpp
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Program's_Contributed_By_Contributors/C++_Programs/add-complex-numbers.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |