C# program to find the addition of two complex numbers
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to demonstrate the addition of two complex numbers is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a class Complex that contains data members real and img. Here we defined two constructors two initialize the values of data members.
Here we overload the binary '+' operator to add two complex numbers, and we also defined a method PrintComplexNumber() to print a complex number on the console screen.
In the Main() method, we created two objects of complex class C1, C2 initialized using parameterized constructor and we created a reference C3.
C3 = C1 + C2;
Here, we assign the sum of C1 and C2 into C3 and then we printed values of all objects.