title: raise a Matrix to the power in c
body: <p>Trying to raise a matrix to the power of p, but I dont find the mistake. Can anyone help and explain the problem? I just got started in programming in C so thank you very much for your help. The user should enter a matrix and it should be raised to the power of p.</p>
  
  <pre><code>int main() {
      int n, p;
      printf("Number of Rows/Colums of square matrix: ");
      scanf("%d", &amp;n);
      printf("to the power of: ");
      scanf("%d", &amp;p);
      int m[n][n];
      int r[n][n];
  
      printf("Elements\n");
      for (int b = 0; b &lt; n; b++) {
          for (int d = 0; d &lt; n; d++) {
              printf("[%d][%d] = ", b + 1, d + 1);
              scanf("%d", &amp;m[b][d]);
          }
      }
  
      int sum = 0;
      for (int i = 0; i &lt; p; i++) {
          for (int b = 0; b &lt; n; b++) {
              for (int d = 0; d &lt; n; d++) {
                  for (int k = 0; k &lt; n; k++) {
                      sum += m[b][k] * m[k][d];
                  }
                  r[b][d] = sum;
                  sum = 1;
              }
          }
  
          for (int b = 0; b &lt; n; b++) {
              for (int d = 0; d &lt; n; d++) {
                  m[b][d] = r[b][d];
                  r[b][d] = 0;
              }
          }
      }
  
      printf("RESULT:-\n");
  
      for (int c = 0; c &lt; n; c++) {
          for (int d = 0; d &lt; n; d++) {
              printf("%d   ", m[c][d]);
          }
          printf("\n");
      }
  
      getch();
      return 0;
  }
  </code></pre>