Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- const int N = 3;
- const int P = 5;
- const int Q = 5;
- const int W = 4; // чтобы провести умножение , то нужно чтобы количество строк 1 матрицы совпадало с количеством столбцов 2 матрицы
- int main()
- {
- int a[N][P];
- int b[Q][W];
- int c[P][Q];
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- cout << " Найтие умножение двух матриц " << endl;
- cout << "Вывод элементов" << endl;
- cout << "Для матрицы А" << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j < P; j++)
- {
- a[i][j] = rand() % 6;
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- cout << "Для матрицы B" << endl;
- for (int i = 0; i < Q; i++)
- {
- for (int j = 0; j < W; j++)
- {
- b[i][j] = rand() % 6;
- cout << b[i][j] << " ";
- }
- cout << endl;
- }
- cout << "Умножение матриц равно = " << endl;
- for (int i = 0; i < N; i++)
- {
- for (int j = 0; j<W; j++)
- {
- c[i][j] = 0;
- for (int k = 0; k < Q; k++)
- {
- c[i][j] += a[i][k] * b[k][j];
- }
- cout << c[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement