Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
795 B
7
Indexable
Never
#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;
}
Leave a Comment