두 개의 3X3 행렬을 곱하는 프로그램을 작성 중입니다. 나는 몇 가지 문제에 부딪 쳤고 문제를 파악할 수 없다. DC++에서 3x3 행렬 곱하기
#include <iostream>
using namespace std;
int main(){
int matrix1[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int matrix2[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int results[3][3];
int product = 0;
int i;
int j;
for (i = 1; i <= 3; i++){
for (j = 1; j <= 3; j++){
product += matrix1[i][j] * matrix2[j][i];
cout << product << endl;
}
results[i][j] = product;
product = 0;
}
cout << endl << "Output Matrix: " << endl;
for (int i = 1; i < 4; i++){
for (int j = 1; j < 4; j++){
cout << results[i][j];
}
cout << endl;
}
system("pause");
return 0;
}
그리고 이것은 내가 나갈 결과입니다 : 어떤 도움을 주시면 감사하겠습니다 사전에 다시
25
73
-1717986851
48
129
-858993331
-1867771963
1566576709
1595991863
Output Matrix:
-858993460-858993460-858993460
-1717986851-858993460-858993460
-85899333112
Press any key to continue . . .
감사합니다! : D
당신이 [] 행렬 1을 삭제'사용하는 이유는, '아소, 당신이 사용하는'new'을 만든 적이 있다면? –
'results [i] [j] = product;'는 내부 루프 몸체 내부에 있어야합니다. –
배열 인덱스가 0에서 크기 - 1로가는 것을 잊어 버리는 것처럼 보입니다. –