#include<bits/stdc++.h>
using namespace std;
int main() {
int a[2][2] = {{1, 2},
{3, 4}};
int b[2][2] = {{5, 6},
{7, 8}};
int mul[2][2];
int sum[2][2];
//sum
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
sum[i][j] = a[i][j]+b[i][j];
}
}
//print summ
cout<<"matrix addition: \n";
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << sum[i][j] << " ";
}
cout << endl;
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
mul[i][j] = 0;
for (int k = 0; k < 2; k++) {
mul[i][k] += a[i][j] * b[j][k];
}
}
}
//print mul
cout<<"matrix multiplication: \n";
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cout << mul[i][j] << " ";
}
cout << endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCiAgICBpbnQgYVsyXVsyXSA9IHt7MSwgMn0sCiAgICAgICAgICAgICAgICAgICB7MywgNH19OwogICAgaW50IGJbMl1bMl0gPSB7ezUsIDZ9LAogICAgICAgICAgICAgICAgICAgezcsIDh9fTsKICAgIGludCBtdWxbMl1bMl07CiAgICBpbnQgc3VtWzJdWzJdOwoKICAgIC8vc3VtCiAgICBmb3IgKGludCBpID0gMDsgaSA8IDI7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgMjsgaisrKSB7CiAgICAgICAgICAgIHN1bVtpXVtqXSA9IGFbaV1bal0rYltpXVtqXTsKICAgICAgICB9CiAgICB9CiAgICAvL3ByaW50IHN1bW0KICAgIGNvdXQ8PCJtYXRyaXggYWRkaXRpb246IFxuIjsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgMjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCAyOyBqKyspIHsKICAgICAgICAgICAgY291dCA8PCBzdW1baV1bal0gPDwgIiAgICAiOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IDI7IGorKykgewogICAgICAgICAgICBtdWxbaV1bal0gPSAwOwogICAgICAgICAgICBmb3IgKGludCBrID0gMDsgayA8IDI7IGsrKykgewogICAgICAgICAgICAgICAgbXVsW2ldW2tdICs9IGFbaV1bal0gKiBiW2pdW2tdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIC8vcHJpbnQgbXVsCiAgICBjb3V0PDwibWF0cml4IG11bHRpcGxpY2F0aW9uOiBcbiI7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IDI7IGorKykgewogICAgICAgICAgICBjb3V0IDw8IG11bFtpXVtqXSA8PCAiICAgICI7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgZW5kbDsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=