You are here

C program to add two complex numbers

C program to add two complex numbers: this program performs addition of two complex numbers which will be entered by the user and then prints it. A user inputs the 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 entered two complex numbers like (1 + 2i) and (4 + 6 i) then the output of the program will be (5 + 8i). A structure is used to store complex number.

Complex numbers program in C language

#include <stdio.h>
struct complex
   int real, img;
int main()
   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 two complex numbers = (%d) + (%di)\n", c.real, c.img);
   return 0;

Download add complex numbers program executable.

C program to add two complex numbers output:
output of c program to add two complex numbers