C++ HW5-2 for WallPower
寫一個C++程式,輸入兩個3X3 A、B矩陣所有元素值後,計算出矩陣AB相乘結果。
參考輸出如下圖。
#include <iostream> using namespace std; int main() { int A[3][3], B[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { cout << "請輸入矩陣A第" << i + 1 << "行第" << j + 1 << "列的元素:"; cin >> A[i][j]; } for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { cout << "請輸入矩陣B第" << i + 1 << "行第" << j + 1 << "列的元素:"; cin >> B[i][j]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << A[i][0] * B[0][j] + A[i][1] * B[1][j] + A[i][2] * B[2][j] << " "; } cout << endl; } system("pause"); return 0; }
留言
張貼留言