   int Col = blockIdx.x*blockDim.x+threadIdx.x;
   if ((Row < n) && (Col < k)) {
     float Cvalue = 0.0;
-    for (int i = 0; i < n; ++i)  Cvalue += A[Row*n+i] * B[Col+i*m];
-    C[Row*n+Col] = Cvalue;
+    for (int i = 0; i < m; ++i)  Cvalue += A[Row*n+i] * B[Col+i*m];
+    C[Row*k+Col] = Cvalue;
   }
 }
 


  for (int i=0; i<N; i++){
    for (int j=0; j<M; j++){
      h_a[j*M+i] = i+j;
    }
  }

  for (int i=0; i<M; i++){
    for (int j=0; j<K; j++){
      h_b[j*K+i] = (i<j ? j:i);
    }
  }

  cudaMemcpy(d_a, h_a, size_a, cudaMemcpyHostToDevice);
  cudaMemcpy(d_b, h_b, size_b, cudaMemcpyHostToDevice);

  dim3 DimGrid((N-1)/16 + 1, (K-1)/16 + 1, 1);
  dim3 DimBlock(16, 16, 1);
  Multy2Matrix <<< DimGrid, DimBlock >>> (M, N, K, d_a, d_b, d_c);

  cudaMemcpy(h_c, d_c, sizeof(float)*N*K, cudaMemcpyDeviceToHost);

  std::cout << "\nA matrix \n";
  for (int i=0; i<N; i++){
    for (int j=0; j<M; j++){
      std::cout << h_a[j*N+i] << " ";
    }
    std::cout << "\n";
  }
