C

Matrix multiplication in C

Në shqip: Shumëzimi i matricave në C

ShpjegimiSQ

Shumëzimi i dy matricave bëhet me tre cikle të ndërthurura: rreshti i së parës shumëzohet me kolonën e së dytës. Ushtrim klasik — dhe me renditjen e duhur të cikleve (i-k-j) bëhet shumë më i shpejtë falë cache-it.

EnglishEN

Multiplying two matrices takes three nested loops: a row of the first times a column of the second. A classic exercise — and with the right loop order (i-k-j) it gets much faster thanks to the cache.

Si ta mendosh

Si tabela e shumëzimit, por për tabela të tëra.

Lexoje në anglisht

Like the times table, but for whole tables.

Shembull kodic

for (int i = 0; i < n; i++)
  for (int k = 0; k < n; k++)
    for (int j = 0; j < n; j++)
      C[i][j] += A[i][k] * B[k][j];

Terma të lidhur