Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //matrix multiple
- #include <iostream>
- #include <vector>
- int main()
- {
- std::cout << "Enter rows amount of matrix 1: ";
- int row_matr_1;
- std::cin >> row_matr_1;
- std::cout << std::endl;
- std::cout << "Enter columns amount of matrix 1: ";
- int col_matr_1;
- std::cin >> col_matr_1;
- std::cout << std::endl;
- std::cout << "Row amount of matrix 2 is equal column amount for matrix 1: " << col_matr_1;
- int row_matr_2 = col_matr_1;
- std::cout << std::endl << std::endl;
- std::cout << "Enter column amount of matrix 2: ";
- int col_matr_2;
- std::cin >> col_matr_2;
- std::cout << std::endl;
- int first[row_matr_1][col_matr_1];
- int second[row_matr_2][col_matr_2];
- int result[row_matr_1][col_matr_2];
- std::cout << "Let's fill the matrix 1:" << std::endl;
- for (int i=0; i<row_matr_1; i++)
- for (int j=0; j<col_matr_1; j++)
- {
- std::cout << "Enter " << j << " item in " << i << " row: ";
- std::cin >> first[i][j];
- };
- std::cout << std::endl;
- std::cout << "Let's fill the matrix 2:" << std::endl;
- for (int i=0; i<row_matr_2; i++)
- for (int j=0; j<col_matr_2; j++)
- {
- std::cout << "Enter " << j << " item in " << i << " row: ";
- std::cin >> second[i][j];
- };
- std::cout << std::endl;
- for (int i=0; i<row_matr_1; i++)
- for (int j=0; j<col_matr_2; j++){
- result[i][j] = 0;
- for (int k=0; k<col_matr_1; k++)
- result[i][j] += first[i][k]*second[k][j];
- };
- std::cout << "The multiple result is:" << std::endl;
- for (int i=0; i<col_matr_1; i++){
- for (int j=0; j<col_matr_2; j++)
- std::cout << result[i][j] << " ";
- std::cout << std::endl;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement