Untitled
unknown
plain_text
a year ago
795 B
14
Indexable
#include <iostream>
using namespace std;
void initializeMatrix(int** mat, int rows, int cols) {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
mat[i][j] = i * j;
}
}
}
void printMatrix(int** mat, int rows, int cols) {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {
cout << mat[i][j] << " ";
}
cout << endl;
}
}
int main() {
int rows = 3, cols = 4;
int** mat = new int*[rows];
for (int i = 0; i < rows; ++i) {
mat[i] = new int[cols];
}
initializeMatrix(mat, rows, cols);
printMatrix(mat, rows, cols);
for (int i = 0; i < rows; ++i) {
delete[] mat[i];
}
delete[] mat;
return 0;
}
Editor is loading...
Leave a Comment