Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4. int main() {
  5.     setlocale(LC_ALL, "rus");
  6.     int i, j, n, m;
  7.     srand(time(0));
  8.     cout << "Введите кол-во строк матрицы:";
  9.     cin >> n;
  10.     cout << "Введите кол-во столбцов матрицы :";
  11.     cin >> m;
  12.     int matr[20][20];
  13.     for (int i = 0; i < n; i++)
  14.         for (j = 0; j < m; j++)
  15.             matr[i][j] = rand() % 2;
  16.     cout << "Матрица №1:\n";
  17.     for (int i = 0; i < n; i++) {
  18.         cout << endl;
  19.         for (int j = 0; j < m; j++) {
  20.             cout << matr[i][j] << "\t";
  21.         }
  22.     }
  23.     int sizeRow, sizeCol;
  24.     cout << "\nВведите количество строк второй матрицы:";
  25.     cin >> sizeRow;
  26.     while (sizeRow != m)
  27.     {
  28.         cout << "Количесвто строк 2й матрцы должно соответствовать количеству столбцов 1й!\n";
  29.         cout << "\nВведите количество строк второй матрицы:";
  30.         cin >> sizeRow;
  31.     }
  32.     cout << "Введите количество столбцов 2й матрицы:";
  33.     cin >> sizeCol;
  34.     int matr2[20][20];
  35.     cout << "Матрица № 2\n";
  36.     for (int i = 0; i < sizeRow; i++)
  37.     {
  38.         cout << endl;
  39.         for (int j = 0; j < sizeCol; j++)
  40.         {
  41.             matr2[i][j] = rand() % 2;
  42.             cout << matr2[i][j] << "\t";
  43.         }
  44.     }
  45.     int matr3[20][20];
  46.     for (int i = 0; i < n; i++)
  47.         for (int j = 0; j < sizeCol; j++)
  48.         {
  49.             matr3[i][j] = 0;
  50.             for (int z = 0; z < sizeRow; z++)
  51.                 matr3[i][j] = matr3[i][j] + matr[i][z] * matr2[z][j];
  52.         }
  53.     cout << "\nРезультат умножения:\n";
  54.     for (int i = 0; i < n; i++)
  55.     {
  56.         cout << endl;
  57.         for (int j = 0; j < sizeCol; j++)
  58.             cout << matr3[i][j] << "\t";
  59.     }
  60.     cout << endl;
  61.     system("pause");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement