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