# C++ Program to Perform Complex Number Multiplication

C++ProgrammingServer Side Programming

Complex numbers are numbers that are expressed as a+bi where i is an imaginary number and a and b are real numbers. Some examples on complex numbers are −

2+3i
5+9i
4+2i

A program to perform complex number multiplication is as follows −

## Example

Live Demo

#include<iostream>
using namespace std;
int main(){
int x1, y1, x2, y2, x3, y3;
cout<<"Enter the first complex number : "<<endl;
cin>> x1 >> y1;

cout<<"\nEnter second complex number : "<<endl;
cin>> x2 >> y2;
x3 = x1 * x2 - y1 * y2;
y3 = x1 * y2 + y1 * x2;
cout<<"The value after multiplication is: "<<x3<<" + "<<y3<<" i ";
return 0;
}

## Output

The output of the above program is as follows

Enter the first complex number : 2 1
Enter second complex number : 3 4
The value after multiplication is: 2 + 11 i

In the above program, the user inputs both the complex numbers. This is given as follows −

cout<<"Enter the first complex number : "<<endl;
cin>> x1 >> y1;

cout<<"\nEnter second complex number : "<<endl;
cin>> x2 >> y2;

The product of the two complex numbers is found by the required formula. This is given as follows −

x3 = x1 * x2 - y1 * y2;
y3 = x1 * y2 + y1 * x2;

Finally, the product is displayed. This is given below −

cout<<"The value after multiplication is: "<<x3<<" + "<<y3<<" i ";
Updated on 25-Jun-2020 08:49:58