Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int matr_multiply_matr(int m_width_0, int m_height_0, int m_width_1, int m_height_1)
- {
- if (m_width_1 != m_height_0)
- {
- cout << endl << "ERROR!" << "number of colomns first matrix <> number of strings of second matrix" << endl;
- return 1;
- }
- int **f_matrix = new int*[m_width_0], **s_matrix = new int*[m_width_1], **res_matrix = new int*[m_width_0], i = 0, j = 0, l = 0;
- for (i = 0; i < m_height_0; i++)
- f_matrix[i] = new int[m_width_0];
- for (i = 0; i < m_height_1; i++)
- s_matrix[i] = new int[m_width_1];
- for (i = 0; i < m_height_1; i++)
- res_matrix[i] = new int[m_width_0];
- cout << "Enter members of first matrix ";
- for (i = 0; i < m_height_0; i++)
- for (j = 0; j < m_width_0; j++)
- cin >> f_matrix[i][j];
- cout << "Enter members of second matrix ";
- for (i = 0; i < m_height_1; i++)
- for (j = 0; j < m_width_1; j++)
- cin >> s_matrix[i][j];
- cout << endl << endl;
- for (i = 0; i < m_height_0; i++)
- {
- for (j = 0; j < m_width_0; j++)
- cout << "|" << f_matrix[i][j] << "| ";
- cout << endl;
- }
- cout << endl << " x" << endl << endl;
- for (i = 0; i < m_height_1; i++)
- {
- for (j = 0; j < m_width_1; j++)
- cout << "|" << s_matrix[i][j] << "| ";
- cout << endl;
- }
- for (i = 0; i < m_height_1; i++)
- for (j = 0; j < m_width_0; j++)
- res_matrix[i][j] = 0;
- for (i = 0; i < m_height_0; i++)
- for (l = 0; l < m_height_1; l++)
- for (j = 0; j < m_width_0; j++)
- res_matrix[i][l] += f_matrix[i][j] * s_matrix[j][l];
- cout << endl << "Result" << endl;
- for (i = 0; i < m_height_0; i++)
- {
- for (j = 0; j < m_width_1; j++)
- cout << "|" << res_matrix[i][j] << "| ";
- cout << endl;
- }
- system("pause");
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement