C++ 程序执行复数乘法
复数是表示为 a+bi 的数字,其中 i 是虚数,a 和 b 是实数。以下是一些复数示例 -
2+3i 5+9i 4+2i
一个执行复数乘法的程序如下 -
示例
#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;
}输出
上述程序的输出如下所示
Enter the first complex number : 2 1 Enter second complex number : 3 4 The value after multiplication is: 2 + 11 i
在上述程序中,用户输入两个复数。这如下所示 -
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 ";
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP