**The Program in C# Program to Calculate Determinant of Given Matrix is given below:**

```
using System;
namespace MatrixDeterminant
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter the number of rows and columns of the matrix below to find the determinant of matrix:");
int rows = int.Parse(Console.ReadLine());
int columns = int.Parse(Console.ReadLine());
int[,] matrix = new int[rows, columns];
Console.WriteLine("Enter the elements of the matrix:");
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
matrix[i, j] = int.Parse(Console.ReadLine());
}
}
int determinant = GetDeterminant(matrix, rows);
Console.WriteLine("Okay, the determinant of the matrix is: " + determinant);
}
static int GetDeterminant(int[,] matrix, int n)
{
int det = 0;
if (n == 1)
{
return matrix[0, 0];
}
int[,] subMatrix = new int[n - 1, n - 1];
int sign = 1;
for (int i = 0; i < n; i++)
{
GetSubMatrix(matrix, subMatrix, 0, i, n);
det += sign * matrix[0, i] * GetDeterminant(subMatrix, n - 1);
sign = -sign;
}
return det;
}
static void GetSubMatrix(int[,] matrix, int[,] subMatrix, 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)
{
subMatrix[i, j++] = matrix[row, col];
if (j == n - 1)
{
j = 0;
i++;
}
}
}
}
}
}
}
```

## Output:

Hello Codeauri Family, enter the number of rows and columns of the matrix below to find the determinant of matrix:

2

2

Enter the elements of the matrix:

198

234

111

456

Okay, the determinant of the matrix is: 64314

## Pro-Tips💡

Here are the steps by steps execution of above program:

- The first line
`using System;`

is a directive that includes the`System`

namespace in the code, which provides access to various types and methods, including the`Console`

class. - The code is inside a namespace
`MatrixDeterminant`

, which acts as a container for the class`Program`

and other types and classes. - The
`Program`

class contains the`Main`

method, which is the entry point of the program. - In the
`Main`

method, the user is prompted to enter the number of rows and columns of the matrix. The`int.Parse`

method is used to parse the input and convert it to an integer. - The
`matrix`

2D array is declared and initialized using the number of rows and columns entered by the user. - The user is then prompted to enter the elements of the matrix, which are stored in the
`matrix`

array. - The determinant of the matrix is calculated by calling the
`GetDeterminant`

method, passing`matrix`

and`rows`

as arguments. - The
`GetDeterminant`

method calculates the determinant of the matrix using recursion. It checks if`n`

is equal to 1, in which case it returns the first element of the matrix. If`n`

is not equal to 1, it calculates the determinant of submatrices. It declares a`subMatrix`

2D array to store the submatrix and calls the`GetSubMatrix`

method to obtain the submatrix. The`sign`

variable is used to keep track of the sign of each element in the calculation of the determinant. The determinant is calculated by adding the product of`sign * matrix[0, i] * GetDeterminant(subMatrix, n - 1)`

for each`i`

in`0`

to`n - 1`

. - The
`GetSubMatrix`

method takes a 2D array`matrix`

, a 2D array`subMatrix`

, an integer`p`

, an integer`q`

, and an integer`n`

as arguments and returns the submatrix of`matrix`

with the`p`

th row and`q`

th column removed. It uses two variables`i`

and`j`

to keep track of the indices of`subMatrix`

. The method iterates over the`row`

from`0`

to`n - 1`

and the`col`

from`0`

to`n - 1`

, and if`row`

is not equal to`p`

and`col`

is not equal to`q`

, it stores the element in`subMatrix`

. If`j`

is equal to`n - 1`

,`j`

is set to`0`

and`i`

is incremented. - Finally, the determinant is displayed on the console.

**Learn C-Sharp ↗**

C-sharp covers every topic to learn about C-Sharp thoroughly.

**Learn C Programming ↗**

C-Programming covers every topic to learn about C-Sharp thoroughly.

**Learn C++ Programming↗**

**Learn C++ Programming↗**

C++ covers every topic to learn about C-Sharp thoroughly.