Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class matrix
- {
- public:
- int n, m;
- int a[100][100];
- void enter_the_matrix()
- {
- cout << "Enter size of matrix: " << endl; //введите размер матрицы
- cin >> n >> m;
- cin.ignore();
- cout << "Enter the matrix: " << endl; //введите матрицу
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cin >> a[i][j];
- cin.ignore();
- }
- }
- }
- void addition_matrix(matrix A, matrix B)
- {
- if (A.n != B.n || A.m != B.m)
- {
- cout << "addition imposible" << endl; //cложение невозможно
- return;
- }
- for (int i = 0; i < A.n; i++)
- {
- for (int j = 0; j < A.m; j++)
- {
- a[i][j] = A.a[i][j] + B.a[i][j];
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- void multiplication_matrix(matrix A, matrix B)
- {
- if (A.m != B.n)
- {
- cout << "multiplication imposible" << endl; //умножение невозможно
- return;
- }
- for (int i = 0; i < A.n; i++)
- {
- for (int j = 0; j < B.m; j++)
- {
- int s = 0;
- for (int k = 0; k < B.n; k++)
- {
- s += A.a[i][k] * B.a[k][j];
- }
- a[i][j] = s;
- cout << s << " ";
- }
- cout << endl;
- }
- }
- void out_matrix()
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- };
- int main()
- {
- matrix A, B;
- A.enter_the_matrix();
- B.enter_the_matrix();
- matrix C;
- cout << " Summ of matrixes" << endl; //cумма матриц
- C.addition_matrix(A, B);
- cout << " Composition of matrixes" << endl; //произведение матриц
- C.multiplication_matrix(A, B);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement