Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pw(int a){
- if(a%2==0)return 1;else return -1;
- }
- float det(vector<vector<float> > &arr, int rows){
- vector<vector<float> > arr2;
- float dett=0,hk;
- if(rows==2){
- dett= (arr[0][0]*arr[1][1]-arr[0][1]*arr[1][0]);
- } else {
- for(int i=0;i<rows;i++){
- hk=arr[0][i];arr2=arr;
- arr2.erase(arr2.begin());
- for(int k=0;k<rows-1;k++)arr2[k].erase(arr2[k].begin()+i);
- dett=dett+pw(i)*hk*det(arr2,rows-1);
- }
- }
- return dett;
- }
- int pw(int a)
- {
- if (a % 2 == 0) return 1; else return -1;
- }
- double det(List<List<double>> arr)
- {
- int rows = arr.Count;
- List<List<double>> arr2;
- double dett = 0, hk;
- if (rows == 2)
- {
- dett = (arr.First().First() * arr.Last().Last() - arr.First().Last() * arr.Last().First());
- }
- else
- {
- for (int i = 0; i < arr.Count; i++)
- {
- hk = arr[0][i]; arr2 = arr;
- arr2.RemoveAt(0);
- foreach (List<double> k in arr2) k.RemoveAt(i);
- dett = dett + pw(i) * hk * det(arr2);
- }
- }
- return dett;
- }
Add Comment
Please, Sign In to add comment