Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Addition of two complex numbers in C

Adding the 2 complex numbers
For example if the given input is like (a+ib) format. Then user must to separate the real and imaginary values first then we do the
same procedure for second give number
We must to add real1+real2 and as same img1+img2
To produce Final result (real+i imganiray) format
#include <stdio.h>
 
struct complex
{
   int real, img;
};
 
main()
{
   struct complex a, b, c;
 
   printf("Enter a and b where a + ib is the first complex number.\n");
   printf("a = ");
   scanf("%d", &a.real);
   printf("b = ");
   scanf("%d", &a.img);
   printf("Enter c and d where c + id is the second complex number.\n");
   printf("c = ");
   scanf("%d", &b.real);
   printf("d = ");
   scanf("%d", &b.img);
 
   c.real = a.real + b.real;
   c.img = a.img + b.img;
 
   if ( c.img >= 0 )
      printf("Sum of two complex numbers = %d + %di\n",c.real,c.img);
   else
      printf("Sum of two complex numbers = %d %di\n",c.real,c.img);
 
   return 0;
}