题目链接
用C++,cmath库里的abs函数就可以了。
#include <iostream>
#include <cmath>
using namespace std;
int n, m;
int a[510][510];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> a[i][j];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j)
cout << abs(a[i][j]) << ' ';
cout << endl;
}
return 0;
}