Advertisement
Guest User

determinant

a guest
May 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int determinant(int a[10][10],int k);
  4. int main()
  5. {
  6. int a[10][10],i,j,k,d;
  7. printf("Enter order:");
  8. scanf("%d",&k);
  9. if(k>10)
  10. {
  11. exit(0);
  12. }
  13. else
  14. {
  15. printf("Enter the matrix:\n");
  16. for(i=0;i<k;i++)
  17. {
  18. for(j=0;j<k;j++)
  19. {
  20. scanf("%d",&a[i][j]);
  21. }
  22. }
  23. d=determinant(a,k);
  24. printf("Determinant is %d.\n",d);
  25. }
  26. return 0;
  27. }
  28. int determinant(int a[10][10],int k)
  29. {
  30. int c,m,n,i,j,b[10][10],det,s=1;
  31. if(k==1)
  32. {
  33. return (a[0][0]);
  34. }
  35. else
  36. {
  37. det=0;
  38. for(c=0;c<k;c++)
  39. {
  40. m=0;
  41. n=0;
  42. for(i=0;i<k;i++)
  43. {
  44. for(j=0;j<k;j++)
  45. {
  46. b[i][j]=0;
  47. if(i!=0 && j!=c)
  48. {
  49. b[m][n]=a[i][j];
  50. if(n<(k-2))
  51. {
  52. n++;
  53. }
  54. else
  55. {
  56. n=0;
  57. m++;
  58. }
  59. }
  60.  
  61. }
  62. }
  63. det=det+s*(a[0][c]*determinant(b,k-1));
  64. s=s*(-1);
  65. }
  66. }
  67. return det;
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement