C Program to Perform Complex Number Multiplication

«
»
This C program performs complex number multiplication. This program generally demonstrates the arithmatic operations on complex numbers.

Here is the source code of the C program to multiply two complex numbers. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

1. `/*`
2. ` * C Program to perform complex number multiplication`
3. ` */`
4. `#include<stdio.h>`
5. `typedef struct COMPLEX{`
6. `    int a;`
7. `    int b;`
8. `}Complex;`
9. `Complex multiply(Complex, Complex);`
10. `int main(){`
11. `    int a1, b1, a2, b2;`
12. `    Complex x, y, z;`
13. `    printf("Enter first complex number : ");`
14. `    scanf("%d+%di", &a1, &b1);`
15. `    printf("\nEnter second complex number : ");`
16. `    scanf("%d+%di", &a2, &b2);`
17. `    x.a = a1;`
18. `    x.b = b1;`
19. `    y.a = a2; `
20. `    y.b = b2;`
21. `    z = multiply(x, y);`
22. `    printf("\nAfter multiplication: %d+%di", z.a, z.b);`
23. `    return 0;`
24. `}`
25. `Complex multiply(Complex x, Complex y){`
26. `    Complex z;`
27. `    z.a = x.a * y.a - x.b * y.b;`
28. `    z.b = x.a * y.b + x.b * y.a;`
29. `    return z;`
30. `}`

```\$ gcc complex.c -o complex
\$ ./complex

Enter first complex number : 2+1i
Enter second complex number : 2+1i
After multiplication: 3+4i```

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!