Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. int determinant(int[3][3]);
  4. void create(int[3][3]);
  5. void display(int[3][3]);
  6. int main()
  7. {
  8. int mat[3][3];
  9. int d;
  10. printf("\n Enter elements of the matrix: ");
  11. create(mat);
  12. printf("\n The Matrix: \n");
  13. display(mat);
  14. d=determinant(mat);
  15. printf("\n The determinant for given matrix: %d",d);
  16. if(d==0)
  17. printf("\n Matrix is singular.");
  18. else
  19. printf("\n Matrix is not singular.");
  20. return 0;
  21. }
  22.  
  23. /* Function used to create a matrix */
  24.  
  25. void create(int mat[3][3])
  26. {
  27. int i,j,element;
  28. for(i=0;i<3;i++)
  29. {
  30. for(j=0;j<3;j++)
  31. {
  32. printf("Enter the element");
  33. scanf("%d",&element);
  34. mat[i][j]=element;
  35. }
  36. }
  37. printf("\n\n");
  38. }
  39.  
  40. /* Function used to display the contents of a matrix */
  41.  
  42. void display(int mat[3][3])
  43. {
  44. int i,j;
  45. for(i=0;i<3;i++)
  46. {
  47. for(j=0;j<3;j++)
  48. {
  49. printf("%d\t",mat[i][j]);
  50. }
  51. printf("\n");
  52. }
  53. printf("\n\n");
  54. }
  55.  
  56. /* Function to calculate the determinant value of a 3x3 matrix */
  57.  
  58. int determinant(int mat[3][3])
  59. {
  60. int i,j,k;
  61. int sum,p;
  62. sum=0;
  63. j=1;
  64. k=2;
  65. for(i=0;i<3;i++)
  66.  
  67. {
  68. p=pow(-1,i);
  69. if(i==2)
  70. k=1;
  71. sum=sum+p*(mat[0][i]*(mat[1][j]*mat[2][k]-mat[2][j]*mat[1][k]));
  72. j=0;
  73. }
  74.  
  75. return sum;
  76. }
Add Comment
Please, Sign In to add comment