Q:

C program to add two complex numbers

0

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 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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include 
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 the complex numbers: (%d) + (%di)\n", c.real, c.img);

   return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now