For example, simply in the process of executing a program, write multMatrix (mat1, mat2, mat3) and then matrices of other sizes, say, multMatrix (mat4, mat5, mat6), but it turned out somehow.

#include "stdafx.h" #include <iostream> #include <Windows.h> using namespace std; const int commonROWSandCOLUMNS = 3; const int numofROWS = 3; const int numofCOLUMNS = 3; void multMatrix(int matrix1[numofROWS][commonROWSandCOLUMNS], int matrix2[commonROWSandCOLUMNS][numofCOLUMNS], int matrix3[numofROWS] [numofCOLUMNS]) { for (int i = 0; i < numofROWS; i++) { for (int i2 = 0; i2 < numofCOLUMNS; i2++) { for (int i3 = 0; i3 < commonROWSandCOLUMNS; i3++) { matrix3[i][i2] += matrix1[i][i3] * matrix2[i3][i2]; } } } } int matrix1[3][3] = { {9,3,4}, {2,8,2}, {1,5,6} }; int matrix2[3][3] ={ { 9,0,0 }, { 1,0,0 }, { 8,0,0} }; int matrix3[3][3]; int main() { multMatrix(matrix1,matrix2,matrix3); for (int i = 0; i < 3; i++) { for (int i2 = 0; i2 < 3; i2++) { cout << matrix3[i][i2]<<" "; } cout << endl; } system("pause"); return 0; } 

Or tell me some library. Or should we use dynamic arrays?

  • What exactly is the question? If you definitely need to represent the matrix is ​​just bare 2D arrays - then this is one question. If the method of matrix representation is not fundamental, then this is a completely different question. - AnT
  • You can overload the function. You can create your own data type, which will represent the matrix, regardless of its size (read about classes or structures, if you do not know how to do it). - Pavel Antspovich
  • I'll tell the library: boost :: qvm. There are already implemented matrices in this library, and you can also define your own types. In addition, it is integrated with the library boost :: geometry (this is if, in addition to matrices, you also need geometric shapes). - Andrej Levkovitch
  • What does the way of matrix representation mean? It is necessary to make a function in which it will be possible to substitute matrices of various sizes, and now the size of the arrays is determined in advance. - Egor Kerber
  • In the standard language of the matrix is ​​always a fixed size. You will need to create your own structure. - AlexGlebe

0