#include /* needed for std::size_t */ #include /* needed for printf */ struct Matrix { const std::size_t m; /* number of rows */ const std::size_t n; /* number of columns */ const std::size_t incRow; const std::size_t incCol; double* data; Matrix(std::size_t m, std::size_t n, std::size_t incRow, std::size_t incCol) : m(m), n(n), incRow(incRow), incCol(incCol), data(new double[m*n]) { } void init() { for (std::size_t i = 0; i < m; ++i) { for (std::size_t j = 0; j < n; ++j) { data[i*incRow + j*incCol] = j * n + i + 1; } } } void print() { for (std::size_t i = 0; i < m; ++i) { std::printf(" "); for (std::size_t j = 0; j < n; ++j) { std::printf(" %4.1lf", data[i*incRow + j*incCol]); } std::printf("\n"); } } }; int main() { Matrix A(7, 8, 1, 7); A.init(); std::printf("A =\n"); A.print(); }