Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int N; // Размер матрицы
- cout << "Enter the size of matrix: ";
- cin >> N;
- // Создали первую матрицу
- int** firstMatrix = new int* [N];
- for (int i = 0; i < N; i++)
- firstMatrix[i] = new int[N];
- // Вторую матрицу
- int** secondMatrix = new int* [N];
- for (int i = 0; i < N; i++)
- secondMatrix[i] = new int[N];
- // И матрицу - результат
- int** result = new int* [N];
- for (int i = 0; i < N; i++)
- result[i] = new int[N];
- // Заполняем первую
- cout << "Fill the first matrix:" << endl;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- {
- cout << "[" << i << "]" << "[" << j << "] = ";
- cin >> firstMatrix[i][j];
- cout << endl;
- }
- // Отступаем
- cout << endl;
- // Заполняем вторую
- cout << "Fill the second matrix:" << endl;
- for (int i = 0; i < N; i++)
- for (int j = 0; j < N; j++)
- {
- cout << "[" << i << "]" << "[" << j << "] = ";
- cin >> secondMatrix[i][j];
- cout << endl;
- }
- cout << endl << "Results:" << endl;
- // ПОдсчёт
- for(int i = 0 ; i < N; i++ )
- {
- for(int j = 0 ; j < N ; j++)
- {
- int temp = 0;
- for (int k = 0; k < N; k++)
- temp += firstMatrix[i][k] * secondMatrix[k][j];
- result[i][j] = temp;
- }
- }
- for(int i = 0; i < N; i++)
- {
- for (int j = 0; j < N; j++)
- cout << result[i][j] << " ";
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement