79461610

Date: 2025-02-23 17:10:59
Score: 0.5
Natty:
Report link

You have a bug related to the matrix indices calculation when you accumulate the output values.

This line:

*(C + i * n) += *(A + i * n + k) * *(B + k * n + j);

Should be changed to:

//----------vvv-----------------------------------------
*(C + i * n + j) += *(A + i * n + k) * *(B + k * n + j);

I.e. you need to add the second index, exactly like you did when you zeroed the output elements before the innermost loop (*(C + i * n + j) = 0;).

Live demo

A side note:
In order to "catch" such bugs, it is recommended to use a debugger.
See: What is a debugger and how can it help me diagnose problems?.

Reasons:
  • Blacklisted phrase (0.5): how can i
  • Blacklisted phrase (1): help me
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-2):
Posted by: wohlstad