How to find determinant of a matrix

How to find determinant of a matrix of order more than 2*2 , i found the code using recursive method on the internet but i can't understand it may be if it's implemented using non-recursive it will be easier to understand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  #include<iostream.h>
#include<conio.h>
#include<math.h>
class matrix
{
      int a[10][10],n;
public:
      matrix();
      void seeMat();
      void detmnt();
};
 
main()
{
      matrix m;
      m.seeMat();m.detmnt();
      getch();
}
 
matrix::matrix()
{
                int i,j;
                cout<<"Enter order f matrix : ";cin>>n;
                cout<<"Enter the elements \n";
                for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                cin>>a[i][j];
}
 
void matrix::seeMat()
{
                int i,j;
                cout<<"The Matrix is\n";
                for(i=0;i<n;i++){
                for(j=0;j<n;j++)
                cout<<a[i][j]<<" ";cout<<"\n";}
}
 
void matrix::detmnt()
{
     int det(int b[10][10],int m);
     cout<<"det is "<<det(a,n);
}
 
int det(int b[10][10],int m)
{
    int sum=0,x=0,y=0,i=0,j,aa,bb,c[10][10];
    if(m==2)
            return(b[0][0]*b[1][1]-b[0][1]*b[1][0]);
    else
    {
        for(j=0;j<m;j++)
        {
                for(aa=0,y=0;aa<m;aa++)
                {
                                for(bb=0;bb<m;bb++)
                                {
                              
                                }
                               if(y>0)x++;
                               y=0;
                }
             sum=sum+b[i][j]*pow(-1,i+j)*det(c,m-1);
        }
    }
    return sum;
}
http://www.mathsisfun.com/algebra/matrix-determinant.html

As for the code, I haven't tested it to see if it works, but from examining it I can see some possible faults:

- i is never incremented in the det(int[][], int) function, but it is used in the calculation on line 63
- c is a matrix containing, God knows what, but it is used in the recursive call to the function (same line 63)

Also note that the for-loop on line 56 does nothing, so...why is it there?
i is never incremented in the det(int[][], int) function, but it is used in the calculation on line 63
- c is a matrix containing, God knows what, but it is used in the recursive call to the function (same line 63)

Also note that the for-loop on line 56 does nothing, so...why is it there?

Yes you are right , sorry i didn't noticed those errors as i copied them from a page and thought it was right but saying all that it's concept and code is on the right track , determinants on different pages are solved through by this method though i can't figure it out how to solve it using coding i understand the concept and solving them on paper.
Topic archived. No new replies allowed.