![]() |
VOOZH | about |
Complex numbers are those numbers that can be expressed in the form of "a+ib" where a and b are the real numbers and i is the imaginary part called "iota" The value of i is √-1. In this article, we are going to add two complex numbers using a C program.
Input: a = ( 2 + 3i ) b = ( 4 + 5i ) Output: Sum = ( 6 + 8i )
Explanation:
= ( 2 + 3i ) + ( 4 + 5i ) = ( 2 + 4 ) + ( 3 + 5 )i = ( 6 + 8i )
The approach is very simple for this program, follow the below steps.
Below is the C program to add two complex numbers:
a = 2 + 3i b = 4 + 5i sum = 6 + 8i
Complex Numbers consist of real and img parts which will be declared as a struct complex. While In the function, int main() there are three instances of structs created a,b, and sum. And then values are assigned to both complex numbers. After assigning the values we are calling add function with a and b as a complex number. add function will return the addition of both objects as a sum.