현재 매개 변수로 3 개의 다른 10x10 배열을 사용하는 함수를 사용하는 프로그램을 작성하려고하고 있으며 첫 번째 배열의 제품으로 세 번째 배열을 채 웁니다.C++에서 두 개의 10x10 배열을 곱하는 방법은 무엇입니까?
나는 시도하고 내 자신의 문제를 파악하기 위해 웹을 흐르고,하지만 지금까지 나는이 마련에만있다 :
는 (I 2의, 두 번째 배열로 첫 번째 배열을 채워 3의), 이것이 내가 3 배열 내의 세포 중 하나를 인쇄 할 때마다 여기 바와 같이하지만, 나는 60를 얻을하지 않습니다 작동해야 내 이해에
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
/************************************************
** Function: populate_array1
** Description: populates the passed array with 2's
** Parameters: 10x10 array
** Pre-Conditions:
** Post-Conditions:
*************************************************/
void populate_array1(int array[10][10])
{
int i, n;
for (i = 0; i<10; i++)
{
for (n = 0; n<10; n++)
{
array[i][n] = 2;
}
}
}
/************************************************
** Function: populate_array2
** Description: populates the passed array with 3's
** Parameters: 10x10 array
** Pre-Conditions:
** Post-Conditions:
*************************************************/
void populate_array2(int array[10][10])
{
int i, n;
for (i = 0; i<10; i++)
{
for (n = 0; n<10; n++)
{
array[i][n] = 3;
}
}
}
/************************************************
** Function: multiply_arrays
** Description: multiplies the first two arrays,
and populates the 3rd array with the products
** Parameters: 3 10x10 arrays
** Pre-Conditions:
** Post-Conditions:
*************************************************/
void multiply_arrays(int array1[10][10], int array2[10][10], int array3[10][10])
{
int i, n, j;
for (i = 0; i<10; i++)
{
for (n = 0; n<10; n++)
{
for (j = 0; j<10; j++)
{
array3[i][n] += array1[i][j]*array2[j][n];
}
}
}
}
int main()
{
int array1[10][10];
int array2[10][10];
int array3[10][10];
populate_array1(array1); // Fill first array with 2's
populate_array2(array2); // Fill second array with 3's
multiply_arrays(array1, array2, array3);
cout << array1[5][2];
cout << endl << array2[9][3];
cout << endl << array3[8][4];
return 0;
}
:
도움을 주시면 감사하겠습니다.
아 것입니다. 고마워. –