title: matrix multiplication as column major
body: <p>I am trying to multiply as column major and I can't seem to find the right formula!
  I want to have the matrices as 1D.</p>
  
  <p>Let's say I have these matrices:</p>
  
  <p>A= </p>
  
  <blockquote>
    <p>1  3</p>
    
    <p>2  4</p>
  </blockquote>
  
  <p>and B=</p>
  
  <blockquote>
    <p>5  2  1</p>
    
    <p>6  3  7</p>
  </blockquote>
  
  <p>The above matrices are assumed that are stored already in column major order.</p>
  
  <p>I am trying:</p>
  
  <pre><code>int main(int argc, const char* argv[]) {
    int rows=2;
    int cols=3;
  
  
    int A[rows*rows];
    int B[rows*cols];
    int res[rows*cols];
  
    A[0]=1;
    A[1]=3;
    A[2]=2;
    A[3]=4;
  
  
    B[0]=5;
    B[1]=2;
    B[2]=1;
    B[3]=6;
    B[4]=3;
    B[5]=7;
  
    /*A[0]=1;
    A[1]=2;
    A[2]=3;
    A[3]=4;
  
  
    B[0]=5;
    B[1]=6;
    B[2]=2;
    B[3]=3;
    B[4]=1;
    B[5]=7;
    */
  
  
    //multiplication as column major
   for (int i=0;i&lt;rows;i++){
     for (int j=0;j&lt;cols;j++){
       res[i+j*rows]=0;
       for (int k=0;k&lt;rows;k++){
      res[i+j*rows]+=A[i+k*rows]*B[k+j*cols];
  
  
     }
  
     }
  }
  
  
  
    for (int i=0;i&lt;rows*cols;i++){
       printf("\n\nB[%d]=%d\t",i,res[i]);
  
    }
  
    return 0; 
  
   }
  </code></pre>
  
  <p>I am not getting the correct results.</p>
  
  <p>Also,I can't understand  (in the case where the matrices are stored in column major already) ,how to index the matrices A and B.</p>
  
  <pre><code> A[0]=1;
  
   A[1]=3;
  
  ...
  </code></pre>
  
  <p>or</p>
  
  <pre><code>  A[0]=1;
  
    A[1]=2;
  ...
  </code></pre>
  
  <p>I don't want to transpose the matrices and then use row major.</p>
  
  <p>I want to handle the data as column major.</p>
  
  <p>Because the indices ,if stored as column major,will be different (hence,will matter in order to do the multiplication).</p>