export module MatMod;
export constexpr int SZ = 5;
export void mat_add(const int A[][SZ],
const int B[][SZ],
int C[][SZ])
{
for (int i = 0; i < SZ; i++)
for (int j = 0; j < SZ; j++)
C[i][j] = A[i][j] + B[i][j];
}
export void mat_mul(const int A[][SZ],
const int B[][SZ],
int C[][SZ])
{
for (int i = 0; i < SZ; i++)
for (int j = 0; j < SZ; j++)
{
C[i][j] = 0;
for (int k = 0; k < SZ; k++)
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}
}
int det_rec(const int A[][SZ], int n)
{
if (n == 1)
return A[0][0];
int s = 0;
for (int k = 0; k < n; k++)
{
int B[SZ][SZ] = {};
int bi = 0;
for (int i = 1; i < n; i++)
{
int bj = 0;
for (int j = 0; j < n; j++)
{
if (j != k)
{
B[bi][bj] = A[i][j];
bj++;
}
}
bi++;
}
if (k % 2 == 0)
s = s + A[0][k] * det_rec(B, n - 1);
else
s = s - A[0][k] * det_rec(B, n - 1);
}
return s;
}
export int mat_det(const int A[][SZ])
{
return det_rec(A, SZ);
}