#include
#include
static int count=0;
int mat[25][25][25];
int det(int order,int mat);
int cofactor(int mat,int order,int i,int j);
void main()
{
int i,j,order,val=0;
clrscr();
printf("Enter the order of the Matrix(Square matrix only):");
scanf("%d",&order);
printf("\n");
for(i=0;i
printf("Enter element [%d][%d]:",i+1,j+1);
scanf("%d",&mat[0][i][j]);
}
if(order==0)
{
printf("Sorry, A matrix must have atleast one element.");
getch();
main();
}
else if(order==1)
val=mat[0][0][0];
else
val=det(order,count);
printf("\nDeterminant of the Matrix is: %d",val);
getch();
}
int det(int order,int term)
{
int i,j,val=0;
if(order==2)
val=mat[term][0][0]*mat[term][1][1]-(mat[term][0][1]*mat[term][1][0]);
else
for(i=0;i
return(val);
}
int cofactor(int term,int order,int i,int j)
{
int value=0;
int p,q,x,y;
int neworder;
neworder=order-1;
count++;
for(x=0,p=0;p
if(p==i)
x++;
for(y=0,q=0;q
if(q==j)
y++;
mat[count][p][q]=mat[loc][x][y];
}
}
value=det(neworder,count);
return(value);
}
No comments:
Post a Comment