Determinant

  1. Enhance your previous exercise of CMatrix by adding a member function Det() so that it can calculate the determinant of a matrix.
  2. Hint: It will be useful to define a helper function CMatrix Minor(int i, int j) to derive the minor of matrix A by eliminating row i and column j from A. With this function, it becomes straightforward to calculate the determinant with a recursive formula.

You may test your CMatrix class with the following main program:
int main()
{
    int n;

    cin >> n;
    CMatrix a(n,n);
    a.Read();
    cout << a.Det() << endl;

    return 0;
}  
  1. For the input
    2
    1 2
    3 4  
    The running result should be
    -2  
  2. For the input
    3
    1 0 0
    0 2 0
    0 0 3  
    The result should be
    6