Matrix Multiplication In C

前端 未结 8 2107
后悔当初
后悔当初 2021-02-10 00:01

I\'m trying to solve a matrix multiplication problem with C. Matrix sizes given in problem (2x2) I wrote this code but it doesn\'t print result as I expect. I think I\'m missing

8条回答
  •  醉梦人生
    2021-02-10 00:38

    The problem is that in the line

    matC[i][j] += matA[i][k] * matB[k][j];
    

    you are adding things to matC, but when you create it, you don't initialize it, so it has garbage.

    You sould do something like:

    int matC[2][2] = {0} which will initialize all the matrix with 0's

提交回复
热议问题