Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <cstdlib>
- using namespace std;
- void MatrixMultiply(int **first_matrix, int **second_matrix, int row, int col, int s){
- int **result = new int *[row];
- for (int i = 0; i < row; i++) {
- result[i] = new int[col];
- }
- cout << "Результат умножения матриц: \n";
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- for (int inn = 0; inn < s; inn++) {
- result[i][j] += first_matrix[i][inn] * second_matrix[inn][j];
- }
- cout << result[i][j] << ' ';
- }
- cout << '\n';
- }
- }
- int main(){
- setlocale(LC_ALL, "russian");
- int n, m, k, l;
- cout << "Введите размерность матриц(n, m, k, l): ";
- cin >> n >> m >> k >> l;
- int **a = new int *[n];
- for (int i = 0; i < n; i++) {
- a[i] = new int [m];
- }
- int **b = new int *[k];
- for (int i = 0; i < k; i++) {
- b[i] = new int [l];
- }
- cout << "Введите элементы первой матрицы: ";
- for (int i = 0; i < n; i++){
- for (int j = 0; j < m; j++){
- cin >> a[i][j];
- }
- }
- cout << "Введите элементы второй матрицы: ";
- for (int i = 0; i < k; i++){
- for (int j = 0; j < l; j++){
- cin >> b[i][j];
- }
- }
- if (m == k) {
- MatrixMultiply(a, b, n, l, m);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment