title: Creating matrices in C++
body: <p>I am relatively new to C++ programming and I wanted to learn more about language by programming matrices. I have this code that works, but I can't figure out how to create code that would work for any amount of columns and rows. I have trouble passing matrices to functions, which have rows and columns determined by user input.</p>
  <p>This is what I have:</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  template &lt;int rows, int cols&gt;
  void display(int (&amp;array)[rows][cols]) {
    int i, j;
    cout&lt;&lt;&quot;\n&quot;;
    for(i = 0; i&lt;rows; i++) {
        for(j = 0; j&lt;cols; j++) {
          cout&lt;&lt;&quot; &quot;;
          cout&lt;&lt;array[i][j];
        }
        cout&lt;&lt;&quot;\n&quot;;
      }
  }
  
  
  int main() {
    int M1[3][3];
    cout&lt;&lt;&quot;Enter your matrix elements: \n&quot;;
    int i, j;
      for(i = 0; i&lt;3; i++) {
        for(j = 0; j&lt;3; j++) {
          cout&lt;&lt;&quot;a[&quot;&lt;&lt;i&lt;&lt;&quot;][&quot;&lt;&lt;j&lt;&lt;&quot;]: &quot;;
          cin&gt;&gt;M1[i][j];
        }
      }
      display(M1);
    return 0;
  }
  </code></pre>
  <p>Is performing such task possible without complicating the code too much?</p>