You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.6 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 110;
int n = 3;
//两个n*n的矩阵
/*
z[][N]:
C++
使
C++
*/
void add(LL z[][N], LL x[][N], LL y[][N]) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
z[i][j] = x[i][j] + y[i][j];
}
void dec(LL z[][N], LL x[][N], LL y[][N]) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
z[i][j] = x[i][j] - y[i][j];
}
/*
1 2 3
1 2 3
1 2 3
4 5 6
4 5 6
4 5 6
:
5 7 9
5 7 9
5 7 9
*/
LL x[N][N], y[N][N], z[N][N];
int main() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> x[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> y[i][j];
add(z, x, y);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
cout << z[i][j] << " ";
cout << endl;
}
dec(z, x, y);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
cout << z[i][j] << " ";
cout << endl;
}
return 0;
}