''''// C++ program to find Determinant of a matrix
''''#include <iostream>
''''using namespace std;
' Hope the above isn't important because WTH?
 
''''// Dimension of input square matrix
''''#define N 4
' Again not sure??  oh this is for testing 4 x 4, the 3 x 3 is commented out
 
 
 
 
''''// Driver program to test above functions
' that are defined below :)
 
''''int main()
''''{
''''    /* int mat[N][N] = {{6, 1, 1},
''''                     {4, -2, 5},
''''                     {2, 8, 7}}; */
 
''''    int mat[N][N] = { { 1, 0, 2, -1 },
''''                      { 3, 0, 0, 5 },
''''                      { 2, 1, 4, -3 },
''''                      { 1, 0, 5, 0 } };
' well crap we need a way to read in a Matrix from a string
 
m$ = "1,2;3,4"
readStr2Mat m$, mat()
displayMat mat(), 2, 2
Print " D ="; determinantOfMatrix%
(mat
(), 2) m$ = "2, -3,1;2,0,-1 ;1, 4, 5"
readStr2Mat m$, mat()
displayMat mat(), 3, 3
Print " D ="; determinantOfMatrix%
(mat
(), 3) m$ = "1, 0, 2, -1;3, 0, 0, 5;2, 1, 4, -3;1, 0, 5, 0 "
readStr2Mat m$, mat()
displayMat mat(), 4, 4
Print " D ="; determinantOfMatrix%
(mat
(), 4)  
''''    // Function call
''''    cout <<"Determinant of the matrix is : " << determinantOfMatrix(mat, N);
''''    return 0;
''''}
 
''''// this code is contributed by shivanisinghss2110
''''Output
 
 
' Move from near start to end
''''// Function to get cofactor of mat[p][q] in temp[][]. n is
''''// current dimension of mat[][]
''''void getCofactor(int mat[N][N], int temp[N][N], int p,
''''                 int q, int n)
 
    'Print "getCoFactor p, q, n: "; p, q, n
 
    ''''{
    ''''    int i = 0, j = 0;
 
    ''''    // Looping for each element of the matrix
    ''''    for (int row = 0; row < n; row++)
    ''''    {
    ''''        for (int col = 0; col < n; col++)
    ''''        {
 
            ''''            //  Copying into temporary matrix only those
            ''''            //  element which are not in given row and
            ''''            //  column
            ''''            if (row != p && col != q)
                ''''            {
                ''''                temp[i][j++] = mat[row][col];
 
                ' is j increased before or after temp(i, j) is assigned???
                temp(i, j) = mat(row, col)
                j = j + 1 ' I think j should be increased after temp copy  so temp(0,0) is filled
                    j = 0: i = i + 1
 
                ''''                // Row is filled, so increase row index and
                ''''                // reset col index
                ''''                if (j == n - 1)
                ''''                {
                ''''                    j = 0;
                ''''                    i++;
                ''''                }
                ''''            }
                ''''        }
                ''''    }
                ''''}
 
 
' also moved
''''/* Recursive function for finding determinant of matrix.
''''   n is current dimension of mat[][]. */
''''int determinantOfMatrix(int mat[N][N], int n)
    ''''{
    ''''    int D = 0; // Initialize result
 
    ''''    //  Base case : if matrix contains single element
    ''''    if (n == 1)
    ''''        return mat[0][0];
 
        determinantOfMatrix% = mat(0, 0)
        ''''    int temp[N][N]; // To store cofactors
        ''''    int sign = 1; // To store sign multiplier
        sign = 1
 
        ''''    // Iterate for each element of first row
        ''''    for (int f = 0; f < n; f++)
 
            ''''    {
            ''''        // Getting Cofactor of mat[0][f]
            ''''        getCofactor(mat, temp, 0, f, n);
            getCofactor mat(), temp(), 0, f, n
            ''''        D += sign * mat[0][f]
            ''''             * determinantOfMatrix(temp, n - 1);
            D = D + sign * mat(0, f) * determinantOfMatrix%(temp(), n - 1)
            ''''        // terms are to be added with alternate sign
            ''''        sign = -sign;
            sign = -sign
            ''''    }
        ''''    return D;
        determinantOfMatrix% = D
    ''''}
 
'also moved
''''/* function for displaying the matrix */
''''void display(int mat[N][N], int row, int col)
    ''''{
    ''''    for (int i = 0; i < row; i++)
    ''''    {
    ''''        for (int j = 0; j < col; j++)
    ''''            cout <<"  " <<  mat[i][j];
    ''''        cout <<"n";
    ' the hell
            ''''    }
            ''''}
 
Sub readStr2Mat 
(s$
, mat
() As Integer) ' commas separate columns, semi-colons separate rows     Split s$, ";", rows$()
        Split rows$(i), ",", nums$()
            mat
(i
, j
) = Val(nums$
(j
)) 
    curpos 
= 1: arrpos 
= LBound(loadMeArray
): LD 
= Len(delim
)    dpos 
= InStr(curpos
, SplitMeString
, delim
)        loadMeArray
(arrpos
) = Mid$(SplitMeString
, curpos
, dpos 
- curpos
)        arrpos = arrpos + 1
        curpos = dpos + LD
        dpos 
= InStr(curpos
, SplitMeString
, delim
)    loadMeArray
(arrpos
) = Mid$(SplitMeString
, curpos
)