Program for calculating Determinant of two 2D matrix


#include<stdio.h>                            //INCLUDING HEADER FILES
#include<math.h>

int mat[20][20],index[20][20],n,d[20];                    //DECLARING GLOBAL VARIABLES
void calc(int);                                //FUNCTION calc() DECLERED HERE

main()                                    //FUNCTION main() STARTS HERE
{
int a,i,j;                            //DECLARING LOCAL VARIABLES FOR main()
printf("\n          ENTER THE ORDER ::");            //GETTING THE ORDER OF DETERMINANT
scanf("%d",&n);
printf("\n          ENTER THE MATRIX ::");            //GETTING THE DETERMINANT
for(i=0;i<n;i++)                        //ROWWISE
for(j=0;j<n;j++)
scanf("%d",&mat[i][j]);
for(i=0;i<n;i++)
index[n-1][i]=i;
a=n-1;
calc(a);                            //CALLING THE FUNCTION calc() WITH PARAMETER a

printf("\n          VALUE OF THE DETERMINANT \n\n");        //PRINTING THE DETERMINANT ...
for(i=0;i<n;i++)
{
printf("             ");
for(j=0;j<n;j++)
printf("%5d",mat[i][j]);
printf("\n");
}
printf("\n          IS EQUAL TO %d\n\n",d[a]);            //....AND ITS VALUE
}                                    //END OF main()

void calc(int i)                            //FUNCTION calc()'S DEFINITION STARTS HERE
{
int j,k,t;                            //DECLARING LOCAL VARIABLES FOR calc()
for(j=0;j<=i;j++)
{
t=0;
for(k=0;k<=i;k++)
{
if(j==k)
continue;
else
{
index[i-1][t]=index[i][k];
t++;
}
}
if(i>2)
calc(i-1);                    //FUNCTION calc() RELOADED
if(i==2)
d[i]+=(mat[n-2][index[1][0]]*mat[n-1][index[1][1]]-mat[n-1][index[1][0]]*mat[n-2][index[1][1]])*mat[n-3][index[i][j]]*pow(-1,(n-i-1)+(index[i][j]));
else
d[i]+=mat[n-i-1][index[i][j]]*d[i-1]*pow(-1,(n-i-1)+(index[i][j]));
   }
}                                    //END OF calc()

, ,

  1. #1 by GarykPatton at June 16th, 2009

    How soon will you update your blog? I’m interested in reading some more information on this issue.

  2. #2 by CrisBetewsky at July 6th, 2009

    It’s a pity that people don’t realize the importance of this information. Thanks for posing it.

  3. #3 by research p at July 13th, 2009

    I have been looking looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.

  4. #4 by financial aid for college at June 24th, 2010

    Keep up the good work, I like your writing.

(will not be published)
  1. No trackbacks yet.