Số phức có dạng a + bi (i là đơn vị ảo, a, b là số thực). Ví dụ: 2+3i, 5+9i, 4+2i.
Ví dụ
#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;
}
Kết quả
Enter the first complex number: 2 1 Enter second complex number: 3 4 The value after multiplication is: 2 + 11 i
Người dùng nhập phần thực và phần ảo của hai số phức:
cout << "Enter the first complex number: " << endl;
cin >> x1 >> y1;
cout << "\nEnter second complex number: " << endl;
cin >> x2 >> y2;
Công thức nhân: (x1 + y1i)(x2 + y2i) = (x1x2 - y1y2) + (x1y2 + y1x2)i
x3 = x1 * x2 - y1 * y2;
y3 = x1 * y2 + y1 * x2;
Hiển thị kết quả:
cout << "The value after multiplication is: " << x3 << " + " << y3 << " i";