C program to add two complex numbers: this program performs addition of two complex numbers which will be entered by a user and then prints it. A user inputs real and imaginary parts of two complex numbers. In our program we will add real parts and imaginary parts of complex numbers and prints the complex number, 'i' is the symbol used for iota. For example, if a user inputs two complex numbers as (1 + 2i) and (4 + 6 i) then the output of the program will be (5 + 8i). A structure is used to store a complex number.
Complex numbers program in C language
int real, img;
struct complex a, b, c;
printf("Enter a and b where a + ib is the first complex number.\n");
scanf("%d%d", &a.real, &a.img);
printf("Enter c and d where c + id is the second complex number.\n");
scanf("%d%d", &b.real, &b.img);
c.real = a.real + b.real;
c.img = a.img + b.img;
printf("Sum of the complex numbers: (%d) + (%di)\n", c.real, c.img);
Download add complex numbers program executable.
C program to add two complex numbers output: