题解 | #创建二维动态数组#
创建二维动态数组
https://www.nowcoder.com/practice/9e55995c4e5345878a31682e4048a0ed
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<vector<int>> arr(n, vector<int>(n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j){ arr[i][j] = i + j; } } for (const auto &row : arr) { for (int num : row) { cout << num << ' '; } cout << endl; } return 0; }