C++ solutions
\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n        int m = nums.size(), n = nums[0].size();\
```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {\n        int m = nums.size(), n = nums[0].size();\n        if (m * n != r * c) {\n            return nums;\n        }\n\n        vector<vector<int>> res(r, vector<int>(c, 0));\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                int k = i * n + j;\n                res[k / c][k % c] = nums[i][j];\n            }\n        }\n\n        return res;\n    }\n};\n```
['C', 'C++']