' ----------------------------------- ' MAIN RECURSIVE FUNCTION ----------- ' THAT ACTUALLY DOES ALL WORK ------- ' ----------------------------------- function determinant(array, size as integer) as floating if size < 2 then Print "Cannot determine determinant!"; while not readkey wend Stop elseif size = 2 then return array[1,1]*array[2,2] - array[2,1]*array[1,2] else sum = 0 for j=1 to size ' Skip zero factors to speed up if (array[1,j] <> 0) then Dim new_a(size,size) ' Creating new matrix for c1=2 to size for c2=1 to size if c2 > j then new_a[c1-1,c2-1] =array[c1,c2] elseif c2 < j then new_a[c1-1,c2]= array[c1,c2] endif Next Next ' Recursive call to get the determinant of smaller matrix. factor = array[1,j]*determinant(new_a, size-1) ' The alternating law applies here if (j mod 2 = 0) then sum = sum - factor else sum = sum + factor endif endif Next return sum endif end function '-------------------------------------------------------------------- ' ------------------------------------------------------------------ '-------------------------------------------------------------------- ConsoleTextColor Rgb(0,0,100) print " Matrix determinant calculation" : print ConsoleTextColor Rgb(0,0,0) Dim size as Integer input " Enter matrix size: ", size Dim Matrix(size,size) 'declare 2 dimension array ' Let's input matrix ------------------------ cls ConsoleTextColor Rgb(0,100,0) for x=1 to size for y=1 to size print " input Matrix[",x,",",y,"]" input " >", Matrix[x,y] next next ' let's print matrix ----------------- cls Print " Your matrix: " ConsoleTextColor Rgb(0,100,0) for x=1 to size dim str as string for y=1 to size str = str + Matrix[x,y] + " " next print " ",str next ' Determinant calculation ------------ Dim Det as floating Det = determinant(Matrix, size) ' ------------------------------------ ConsoleTextColor Rgb(125,125,125) print : print " Determinant = ", Det ConsoleTextColor 0 InfoBox "Press any key to exit" while not readkey wend