Advertisement
doctor900

Untitled

May 24th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. int matr_multiply_matr(int m_width_0, int m_height_0, int m_width_1, int m_height_1)
  2. {
  3.     if (m_width_1 != m_height_0)
  4.     {
  5.         cout << endl << "ERROR!" << "number of colomns first matrix <> number of strings of second matrix" << endl;
  6.         return 1;
  7.     }
  8.    
  9.     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;
  10.  
  11.     for (i = 0; i < m_height_0; i++)
  12.         f_matrix[i] = new int[m_width_0];
  13.     for (i = 0; i < m_height_1; i++)
  14.         s_matrix[i] = new int[m_width_1];
  15.     for (i = 0; i < m_height_1; i++)
  16.         res_matrix[i] = new int[m_width_0];
  17.  
  18.     cout << "Enter members of first matrix ";
  19.     for (i = 0; i < m_height_0; i++)
  20.         for (j = 0; j < m_width_0; j++)
  21.             cin >> f_matrix[i][j];
  22.     cout << "Enter members of second matrix ";
  23.     for (i = 0; i < m_height_1; i++)
  24.         for (j = 0; j < m_width_1; j++)
  25.             cin >> s_matrix[i][j];
  26.  
  27.  
  28.     cout << endl << endl;
  29.     for (i = 0; i < m_height_0; i++)
  30.         {
  31.             for (j = 0; j < m_width_0; j++)
  32.                 cout << "|" << f_matrix[i][j] << "| ";
  33.             cout << endl;
  34.         }
  35.     cout << endl << " x" << endl << endl;
  36.     for (i = 0; i < m_height_1; i++)
  37.             {
  38.                 for (j = 0; j < m_width_1; j++)
  39.                     cout << "|" << s_matrix[i][j] << "| ";
  40.                 cout << endl;
  41.             }
  42.  
  43.         for (i = 0; i < m_height_1; i++)
  44.             for (j = 0; j < m_width_0; j++)
  45.                 res_matrix[i][j] = 0;
  46.  
  47.         for (i = 0; i < m_height_0; i++)
  48.             for (l = 0; l < m_height_1; l++)
  49.                 for (j = 0; j < m_width_0; j++)
  50.                     res_matrix[i][l] += f_matrix[i][j] * s_matrix[j][l];
  51.  
  52.         cout << endl << "Result" << endl;
  53.     for (i = 0; i < m_height_0; i++)
  54.             {
  55.                 for (j = 0; j < m_width_1; j++)
  56.                     cout << "|" << res_matrix[i][j] << "| ";
  57.                 cout << endl;
  58.             }
  59.     system("pause");
  60.     return 0;
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement