Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <iomanip>
- using namespace std;
- void main(void)
- {// Определение переменных
- int
- a[3][3], b[3][3], c[3][3], d[3][3], i, j, m, n, m1, n1, f, l, max;
- cout << "vvedite pa3Mep Matrici A:" << endl;
- cin >> n;
- cin >> m;
- cout << "vvedite pa3Mep Matrici B:" << endl;
- cin >> n1;
- cin >> m1;
- // проверка размерности матриц
- if (n1 >= m1)
- {
- max = n1;
- }
- else
- {
- max = m1;
- }
- if ((n == m) & (n == max))
- { // Заполнение матрицы А
- cout << "vvedite elementi Matrici A:" << endl;
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= m; j++)
- cin >> a[i][j];
- }
- // Заполнение матрицы B
- cout << "vvedite elementi Matrici B:" << endl;
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= m1; j++)
- cin >> b[i][j];
- }
- // Транспонирование матрицы В
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= m1; j++)
- {
- d[j][i] = b[i][j];
- }
- }
- // Умножение матриц В на В транспонированную
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= n1; j++)
- {
- f = 0;
- for (l = 1; l <= m1; l++)
- {
- f = f + b[i][l] * d[l][j];
- }
- c[i][j] = f;
- }
- }
- // Сложение матриц
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= n1; j++)
- {
- c[i][j] = a[i][j] + c[i][j];
- }
- }
- // Вывод матрицы A на экран
- printf("Matrica A: \n");
- for (i = 1; i <= n; i++)
- {
- for (j = 1; j <= m; j++)
- cout << setw(m) << a[i][j];
- cout << endl;
- }
- // Вывод матрицы B на экран
- printf("Matrica B: \n");
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= m1; j++)
- cout << setw(m) << b[i][j];
- cout << endl;
- }
- // Вывод матрицы B транспонированной на экран
- printf("Matrica B(tpaHcnoHupoBaHHa9): \n");
- for (i = 1; i <= m1; i++)
- {
- for (j = 1; j <= n1; j++)
- cout << setw(n) << d[i][j];
- cout << endl;
- }
- // Вывод матрицы C на экран
- cout << "matrica C: \n";
- cout << endl;
- for (i = 1; i <= n1; i++)
- {
- for (j = 1; j <= n1; j++)
- cout << setw(n1) << c[i][j];
- cout << endl;
- }
- }
- else printf("Error!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement