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 ";