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.
/*
* C Program to perform complex number multiplication
*/
#include<stdio.h>
typedef struct COMPLEX{
int a;
int b;
}Complex;
Complex multiply(Complex, Complex);
int main(){
int a1, b1, a2, b2;
Complex x, y, z;
printf("Enter first complex number : ");
scanf("%d+%di", &a1, &b1);
printf("\nEnter second complex number : ");
scanf("%d+%di", &a2, &b2);
x.a = a1;
x.b = b1;
y.a = a2;
y.b = b2;
z = multiply(x, y);
printf("\nAfter multiplication: %d+%di", z.a, z.b);
return 0;
}
Complex multiply(Complex x, Complex y){
Complex z;
z.a = x.a * y.a - x.b * y.b;
z.b = x.a * y.b + x.b * y.a;
return z;
}
$ 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!
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Computer Science MCQs
- Apply for C Internship
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Apply for Computer Science Internship