
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to Perform Complex Number Multiplication
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 of complex numbers are ?
- 2+3i
5+9i
4+2i
Example
A program to perform complex number multiplication is as follows ?
#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
Explanation
In the above program, the user inputs both 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 ";
Advertisements