С++
Найдите значение указанного матричного выражения
Ответ
5 (1 оценка)
1
olegsorokin02 1 год назад
Светило науки - 62 ответа - 0 раз оказано помощи

Ответ:

Объяснение:

#include <iostream>

using namespace std;

void mulMat(int (&mat1)[3][3], int (&mat2)[3][3], int (&res)[3][3])

{

   for (int i = 0; i < 3; i++) {

       for (int j = 0; j < 3; j++) {

           res[i][j] = 0;

           for (int k = 0; k < 3; k++) {

               res[i][j] += mat1[i][k] * mat2[k][j];

           }

       }

   }

}

void addMat(int (&mat1)[3][3], int (&mat2)[3][3], int (&res)[3][3])

{

   for (int i = 0; i < 3; i++) {

       for (int j = 0; j < 3; j++) {

           res[i][j] = mat1[i][j] + mat2[i][j];

       }

   }

}

void subMat(int (&mat1)[3][3], int (&mat2)[3][3], int (&res)[3][3])

{

   for (int i = 0; i < 3; i++) {

       for (int j = 0; j < 3; j++) {

           res[i][j] = mat1[i][j] - mat2[i][j];

       }

   }

}

void printres(int (&res)[3][3]) {

   for (int i = 0; i < 3; i++) {

       for (int j = 0; j < 3; j++) {

           cout << res[i][j] << ' ';

       }

       cout << endl;

   }

}

int main()

{

   int a[3][3] = {{1, 0, 3}, {7, -2, 1}, {3, 2, -6}};

   int b[3][3] = {{-2, 5, -2}, {1, 2, 3}, {-3, 0, -1}};

   int asqr[3][3], bsqr[3][3], b_minus_a[3][3], a_plus_b[3][3], res[3][3];

   int i, j;

   subMat(b, a, b_minus_a);

   addMat(a, b, a_plus_b);

   mulMat(a_plus_b, b_minus_a, res);

   mulMat(a, a, asqr);

   mulMat(b, b, bsqr);

   addMat(res, asqr, res);

   subMat(res, bsqr, res);

   printres(res);

   return 0;

}

Остались вопросы?