using
System;
class
GFG
{
static
readonly
int
N = 3;
static
void
getCofactor(
int
[,]mat,
int
[,]temp,
int
p,
int
q,
int
n)
{
int
i = 0, j = 0;
for
(
int
row = 0; row < n; row++)
{
for
(
int
col = 0; col < n; col++)
{
if
(row != p && col != q)
{
temp[i, j++] = mat[row, col];
if
(j == n - 1)
{
j = 0;
i++;
}
}
}
}
}
static
int
isSingular(
int
[,]mat,
int
n)
{
int
D = 0;
if
(n == 1)
{
return
mat[0, 0];
}
int
[,]temp =
new
int
[N, N];
int
sign = 1;
for
(
int
f = 0; f < n; f++)
{
getCofactor(mat, temp, 0, f, n);
D += sign * mat[0, f] * isSingular(temp, n - 1);
sign = -sign;
}
return
D;
}
public
static
void
Main(String[] args)
{
int
[,]mat = {{4, 10, 1},
{0, 0, 0},
{1, 4, -3}};
if
(isSingular(mat, N) == 1)
{
Console.WriteLine(
"Matrix is Singular"
);
}
else
{
Console.WriteLine(
"Matrix is non-singular"
);
}
}
}