1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
#include <cstddef> /* needed for std::size_t and std::ptrdiff_t */
#include <printf.hpp> /* needed for fmt::printf */

struct Matrix {
   std::size_t m; /* number of rows */
   std::size_t n; /* number of columns */
   std::ptrdiff_t incRow;
   std::ptrdiff_t incCol;
   double* data;

   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 * m + i + 1;
         }
      }
   }
};

void print_matrix(std::size_t m, std::size_t n,
      const double* A, std::ptrdiff_t incRowA, std::ptrdiff_t incColA) {
   for (std::size_t i = 0; i < m; ++i) {
      fmt::printf("  ");
      for (std::size_t j = 0; j < n; ++j) {
         fmt::printf(" %4.1lf", A[i*incRowA + j*incColA]);
      }
      fmt::printf("\n");
   }
}

int main() {
   Matrix A;
   A.m = 7; A.n = 8;
   A.data = new double[A.m * A.n];
   A.incRow = 1; A.incCol = 7;
   A.init();
   fmt::printf("A =\n");
   print_matrix(A.m, A.n, A.data, A.incRow, A.incCol);
   delete[] A.data;
}