title: matrix multipication in c
body: <p>i know there are similiar questions but i tried the suggestions there and it still does not work, here my complete code;</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  void ludec(int N, double lu[N][N]){
      double temp;
      int k,i,j;
      for(k=0;k&lt;N;k++){
          for(i=k+1;i&lt;N;i++){
              temp=lu[i][k]/=lu[k][k];
              for(j=k+1;j&lt;N;j++){
                  lu[i][j]-=temp*lu[k][j];
              }
          }
      }
  }
  void matmul(int u,int m,int n,double p[u][m],double bb[m][n]){
      double mul[u][n];
  
      int ii,jj,kk;
      for(ii=0;ii&lt;u;ii++){
          for(jj=0;jj&lt;n;jj++){
              mul[ii][jj]=0.0;
          }
      }
      for(ii=0;ii&lt;u;ii++){
          for(jj=0;jj&lt;n;jj++){
              for(kk=0;kk&lt;m;kk++){
                  mul[ii][jj]=mul[ii][jj]+p[ii][kk]*bb[kk][jj];
                  printf("la %f ii %d jj%d kk%d\n",mul[ii][jj],ii,jj,kk);
              }
          }
      }
  
  }
  
  int main(void){
      double lu[3][3]={{4.0,3.0,-2.0},{-1.0,-1.0,3.0},{2.0,-1.0,5.0}};
      double a[3][3]={{4.0,3.0,-2.0},{-1.0,-1.0,3.0},{2.0,-1.0,5.0}};
      double y[3][1];
      double b[3][1]={{9.0},{-4.0},{6.0}};
      double x[3][1];
      int i,j,N=3;
      double f=0;
      ludec(N, lu);
      y[0][0]=b[0][0];
      for(i=1;i&lt;3;i++){
          for(j=0;j&lt;i;j++){
               f+=lu[i][j]*y[j][0];
  
           }
           y[i][0]=(b[i][0]-f);
           f=0;
       }
       f=0;
  
  
  
       x[2][0]=y[2][0]/lu[2][2];
       for(i=1;i&gt;=0;i--){
  
          for(j=1+i;j&lt;3;j++){
               f+=lu[i][j]*x[j][0];
  
          }
           x[i][0]=(y[i][0]-f)/lu[i][i];
           f=0;
  
       }
       printf("%f\n %f\n %f\n",x[0][0],x[1][0],x[2][0]);      
      for(i=0;i&lt;3;i++){
          for(j=0;j&lt;3;j++){
              printf("%f %d %d\n",lu[i][j],i,j);
          }
      }
  
  
  
      double mul[3][1];
      matmul(3,3,1,a,x);
      for(i=0;i&lt;3;i++){
          for(j=0;j&lt;2;j++){
              printf("%f %d %d\n",mul[i][j],i,j);
          }
      }
  
      return 0.0;
  }
  </code></pre>
  
  <p>here is the part responsible by multiplication;
  the problem is<br>
  i have to get 3*1 matrix as result in matrix multiplication, but it gives bigger matrix with alot of garbage elements i monitor the matrix multiplication by printf in the matmul function and it seems to work but when i do same out side the matmul function it gives garbage only some values are correct with a lot of useless wrong elements.</p>
  
  <pre><code>void matmul(int u,int m,int n,double p[u][m],double bb[m][n]){
          double mul[u][n];
  
      int ii,jj,kk;
      for(ii=0;ii&lt;u;ii++){
          for(jj=0;jj&lt;n;jj++){
              mul[ii][jj]=0.0;
          }
      }
      for(ii=0;ii&lt;u;ii++){
          for(jj=0;jj&lt;n;jj++){
              for(kk=0;kk&lt;m;kk++){
                  mul[ii][jj]=mul[ii][jj]+p[ii][kk]*bb[kk][jj];
                  printf("la %f ii %d jj%d kk%d\n",mul[ii][jj],ii,jj,kk);
              }
          }
      }
  
  }
  </code></pre>
  
  <p>the problem is matmul function and i dont know why it does not work i already initialized the matrix with zeros. am i using void function property wrong?
  i am very new to c hence there may be something i am doing wrong. the overall code is for lu decompositation, and i want to see wheter the code works or not by multiplying result with initial matrix. </p>
  
  <p><a href="http://i.stack.imgur.com/Tg575.png" rel="nofollow">this is the out put</a></p>