Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,d,b[10][10];
  4. double determinant( int m[10][10], int n) {
  5. int det=0;
  6. int sub[10][10];
  7. if(n==1)
  8. return m[1][1];
  9. else{
  10. for(int x=0;x<=n;x++){
  11. int subi=0;
  12. for(int i=2;i<=n;i++){
  13. int subj=0;
  14. for(int j=1;j<=n;j++){
  15. if(j==x)
  16. continue;
  17. sub[subi][subj]=m[i][j];
  18. subj++;
  19. }
  20. subi++;
  21. }
  22. det=det+(pow(-1, x)*m[1][x]*determinant(sub,n-1));
  23. }
  24. }
  25. return det;
  26. }
  27. int main(){
  28. ifstream cin("prob.in");
  29. ofstream cout("prob.out");
  30. cin>>n;
  31. for(int i=1;i<=n;i++)
  32. for(int j=1;j<=n;j++)
  33. cin>>b[i][j];
  34. cout<<"Avem matricea:"<<endl;
  35. for(int i=1;i<=n;i++){
  36. for(int j=1;j<=n;j++)
  37. cout<<b[i][j]<<' ';
  38. cout<<endl;
  39. }
  40. cout<<"Determinantul="<<setprecision(2)<<fixed<<determinant(b,n);
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement