Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- srand(time(0));
- const int nrows = 3, ncols = 3;
- int A[nrows][ncols], B[nrows][ncols], C[nrows][ncols];
- cout << "Матрицы A и B: \n";
- for (int i = 0; i < nrows; i++) { // вывод и заполнение матриц А и В
- for (int j = 0; j < ncols; j++)
- cout << setw(5) << (A[i][j] = -9 + rand() % 19);
- cout << " ";
- for (int j = 0; j < ncols; j++)
- cout << setw(5) << (B[i][j] = -9 + rand() % 19);
- cout << endl;
- }
- for (int i = 0; i < nrows; i++) //заполнение матрицы произведения нулями
- {
- for (int j = 0; j < ncols; j++)
- {
- C[i][j] = 0;
- }
- }
- for (int i = 0; i < nrows; i++) //произведение матриц А и В
- {
- for (int j = 0; j < ncols; j++)
- {
- for (int k = 0; k < nrows; k++)
- {
- C[i][j] += A[i][k] * B[k][j];
- }
- }
- }
- cout << endl << "Произведение матриц А*В : " << endl;
- for (int i = 0; i < nrows; i++) //вывод матрицы произведения
- {
- for (int j = 0; j < ncols; j++)
- {
- if (j == ncols - 1) {
- cout << setw(5) << C[i][j] << endl;
- }
- else
- cout << setw(5) << C[i][j];
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement