# Inverse of matrix

Program to find inverse of nth order square matrix?(c++)

Showing Answers 1 - 1 of 1 Answers

#### Sandhya.Kishan Profile Answers by Sandhya.Kishan

• May 29th, 2012

void trans(float num,float fac,float r)

{
int i,j;
float b,inv,d;
for(i=0;i {
for(j=0;j {
b[i][j]=fac[j][i];
}
}

d=detrm(num,r);
inv[i][j]=0;
for(i=0;i {
for(j=0;j {
inv[i][j]=b[i][j]/d;
}
}

printf("
THE INVERSE OF THE MATRIX:
");
for(i=0;i {
for(j=0;j {
printf(" %f",inv[i][j]);
}
printf("
");
}
}

we need determinant to find the inverse
The program for determinant is
float detrm(float a,float k)
{
float s=1,det=0,b;
int i,j,m,n,c;
if(k==1)
{
return(a);
}
else
{
det=0;
for(c=0;c {
m=0;
n=0;
for(i=0;i {
for(j=0;j {
b[i][j]=0;
if(i!=0&&j!=c)
{
b[m][n]=a[i][j];
if(n<(k-2))
n++;
else
{
n=0;
m++;
}
}
}
}
det=det+s*(a[c]*detrm(b,k-1));
s=-1*s;
}
}
return(det);
}

Was this answer useful?  Yes

### Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.  