Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. double computeDeterminant(double matrix[255][255], unsigned char start, unsigned char end)
  3. {
  4. int i,j;
  5. double produs,produsmem;
  6. if(start!=end)
  7. {
  8. //Pas 2
  9. for(j=start+1; j<=end; j++)
  10. {
  11. if(matrix[start][j]!=0)
  12. {
  13. produs=1;
  14. produs*=matrix[start][start]/matrix[start][j];
  15. for(i=start; i<=end; i++)
  16. {
  17. matrix[i][j]*=produs;
  18. }
  19. produsmem*=produs;
  20. //Pas 3
  21. for(j=start+1; j<=end; j++)
  22. {
  23. for(i=start; i<=end; i++)
  24. {
  25. matrix[i][j]-=matrix[i][start];
  26. }
  27. }
  28. //Pas 4
  29. return matrix[start][start]*computeDeterminant(matrix,start+1,end)/produsmem;
  30. }
  31. //Pas 1
  32. else
  33. {
  34. for (i=start; i<=end; i++)
  35. {
  36. if (matrix[start][i]!=0)
  37. {
  38. for (j=start; j<=end; j++)
  39. {
  40. matrix[j][start]=matrix[i][start];
  41.  
  42. }
  43. break;
  44. }
  45.  
  46. }
  47. }
  48. }
  49. }
  50. else return 1;
  51.  
  52. }
  53. int main()
  54. {
  55. int n;
  56. double matrix[255][255];
  57. unsigned char start,end;
  58. scanf("%d",&n);
  59. printf("%.2elf",computeDeterminant(matrix, 0, n-1));
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement