Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- using size_type = std::size_t;
- using value_type = int;
- const size_type n1 = 3, n2 = 3;
- value_type m1[n1][n2], m2[n1][n2];
- // 1
- for (int i = 0; i < n1; ++i)
- {
- for (int j = 0; j < n2; ++j)
- {
- int inp; cin >> inp;
- m1[i][j] = inp;
- m2[(n1 - 1) - i][(n2 - 1) - j] = inp;
- }
- }
- cout << endl;
- // 2
- cout << "Mat 1: " << endl;
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- cout << m1[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- cout << "Mat 2: " << endl;
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- cout << m2[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- // 3
- value_type sums[n1][n2];
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- sums[i][j] = m1[i][j] + m2[i][j];
- }
- value_type prods[n1][n2];
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- {
- int mini_sum = 0;
- for (int k = 0; k < n1; ++k)
- {
- mini_sum += m1[i][k] * m2[k][j];
- }
- prods[i][j] = mini_sum;
- }
- }
- cout << "Sums: " << endl;
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- cout << sums[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- cout << "Prods: " << endl;
- for (int i = 0; i < n1; i++)
- {
- for (int j = 0; j < n2; j++)
- cout << prods[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement