0

# Calculate determinants of a nxn matrix in C programming?

Wiki User

2011-01-23 19:37:00

from:

http://local.wasp.uwa.edu.au/~pbourke/other/determinant/

/*

Recursive definition of determinate using expansion by minors.

*/

double Determinant(double **a,int n)

{

int i,j,j1,j2;

double det = 0;

double **m = NULL;

if (n < 1) { /* Error */

} else if (n j1)

continue;

m[i-1][j2] = a[i][j];

j2++;

}

}

det += pow(-1.0,1.0+j1+1.0) * a[0][j1] * Determinant(m,n-1);

for (i=0;i<n-1;i++)

free(m[i]);

free(m);

}

}

return(det);

}

//New Answer By Shaikh SOHIAL Hussain form Pakistan

#include<stdio.h>

#include<conio.h>

void main ()

{ clrscr();

int a[10][10],row,i=0,j=0,result,w,x,y,z;

printf("This Program made 4 solve matrix determintae\n");

scanf("%d",&row);

while(i<row)

{printf("\n");

for(j=0;j<row;j++)

{ printf("Enter the value of %d%d\n",i,j);

scanf("%d",&a[i][j]);

}

i++;

}

i=0;

while(i<row)

{ printf("\n");

j=0; while( j<row)

{printf("%d",a[i][j]);

printf(" ");printf(" ");

j++;}

i++;

}

if(row==2)

{

result=(a[0][0]*a[1][1])-(a[0][1]*a[1][0]);

}

else if(row==3)

{ result=(a[0][0]*((a[1][1]*a[2][2])-(a[1][2]*a[2][1]))) - (a[0][1]*((a[1][0]*a[2][2])-(a[1][2]*a[2][0]))) + (a[0][2]*((a[1][0]*a[2][1])-(a[1][1]*a[2][0])));

}

else if(row==4)

{

w=a[0][0]*(a[1][1]*(a[2][2]*a[3][3]-a[2][3]*a[3][2])-a[1][2]*(a[2][1]*a[3][3]-a[2][3]*a[3][1])+a[1][3]*(a[2][1]*a[3][2]-a[2][2]*a[3][1]));

x=a[0][1]*(a[1][0]*(a[2][2]*a[3][3]-a[2][3]*a[3][2])-a[1][2]*(a[2][0]*a[3][3]-a[2][3]*a[3][0])+a[1][3]*(a[2][0]*a[3][2]-a[2][2]*a[3][0]));

y=a[0][2]*(a[1][0]*(a[2][1]*a[3][3]-a[2][3]*a[3][1])-a[1][1]*(a[2][0]*a[3][3]-a[2][3]*a[3][0])+a[1][3]*(a[2][0]*a[3][1]-a[2][1]*a[3][0]));

z=a[0][3]*(a[1][0]*(a[2][1]*a[3][2]-a[2][2]*a[3][1])-a[1][1]*(a[2][0]*a[3][2]-a[2][2]*a[3][0])+a[1][2]*(a[2][0]*a[3][1]-a[2][1]*a[3][0]));

result=w-x+y-z;

printf("\n The answer is \t %d", result);

}

else{ printf("Determinate Limit is 4*4 max\n");

getch();

}

Wiki User

2011-01-23 19:37:00
Study guides

20 cards

➡️
See all cards
3.75
844 Reviews