Saturday, August 21, 2010

Article | C Program To Find The Determinant of Matrix

To Find The Determinant of Matrix in program C



  1. #include<stdio.h>

  2. #include<conio.h>

  3. #define LIMIT 10

  4. void main()

  5. {

  6. int chckdgnl();

  7. float deter();

  8. float a[LIMIT][LIMIT],value;

  9. int i,j,order;

  10. clrscr();

  11. printf("Enter order of determent :");

  12. scanf("%d",&order);

  13. for(i=0;i<order;i++)

  14. {

  15. for(j=0;j<order;j++)

  16. {

  17. printf("Enter (%d,%d) element of the determent :",i+1,j+1);

  18. scanf("%f",&a[i][j]);

  19. }

  20. }


  21. if(chckdgnl(a,order)==0)

  22. value=0;

  23. else

  24. value=deter(a,order);

  25. printf("Determinent Value :%f",value);

  26. getch();

  27. }


  28. float deter(float a[][LIMIT],int forder)

  29. {

  30. int i,j,k;

  31. float mult;

  32. float deter=1;

  33. for(i=0;i<forder;i++)

  34. {

  35. for(j=0;j<forder;j++)

  36. {

  37. mult=a[j][i]/a[i][i];

  38. for(k=0;k<forder;k++)

  39. {

  40. if(i==j) break;

  41. a[j][k]=a[j][k]-a[i][k]*mult;

  42. }

  43. }

  44. }

  45. for(i=0;i<forder;i++)

  46. {

  47. deter=deter*a[i][i];

  48. }

  49. return(deter);

  50. }



  51. int chckdgnl(float array[][LIMIT],int forder)

  52. {

  53. int i,j,k;

  54. float nonzero;

  55. for(i=0;i<forder;i++)

  56. {

  57. if(array[i][i]==0)

  58. {

  59. for(j=0;j<forder;j++)

  60. {

  61. if(array[i][j]!=0)

  62. {

  63. k=j;

  64. break;

  65. }

  66. if(j==(forder)) //forder-1

  67. return(0);

  68. }

  69. for(j=0;j<forder;j++)

  70. {

  71. array[j][i]=array[j][i]-array[j][k];

  72. }

  73. }

  74. }

  75. return(1);

  76. }


Loading...

Comments :

0 comments to “ C Program To Find The Determinant of Matrix ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers