title: Passing matrix as a parameter
body: <p>I am new to c, I am using CUDA compiler. I want to declare five matrices, from a[1][1] to a[5][5]. Initialize them with random values. Print these values. I have shown the whole code I wrote. I face problems</p>
  
  <ol>
  <li><p>Passing matrix as parameter </p></li>
  <li><p>Initialize a matrix (should be constant)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void printMatrix(int **a, int rows, int cols)
  {
      for(int i=0; i&lt;rows; i++){
          for (int j=0; j&lt;cols; j++){
              printf("%d\t", a[i][j] );
          }
          printf("\n");
      }
  }
  
  int main() {
      int N;
  
      for (int n=0; n&lt;=5; n++)
          N = n;
          int a[N][N];
  
          for(int i=0; i&lt;N; i++)
              for (int j=0; j&lt;N; j++){
                  a[i][j] = rand() % 256;
              }
  
          printf("Matrix A\n");
          printMatrix(a, 10, 10);
      }
  }
  </code></pre>
  
  <p>This works fine if i define N on the top. If I did that, I couldn't change N value using for loop. How can I correct.</p></li>
  </ol>