C program to find the Inverse of a matrix. To find the Matrix Inverse, matrix should be a square matrix and Matrix Determinant is should not Equal to Zero. if A is a Square matrix and |A|!=0, then AA’=I (I Means Identity Matrix). Read more about C Programming Language .
[nextpage title=”PROGRAM” ][message_box title=”Program” color=”yellow”]
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main(){
int a[3][3],i,j;
float determinant=0;
clrscr();
printf(“Enter the 9 elements of matrix: “);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(“%d”,&a[i][j]);
printf(“\nThe matrix is\n”);
}
}
for(i=0;i<3;i++){
printf(“\n”);
for(j=0;j<3;j++)
{
printf(“%d\t”,a[i][j]);
}
}
for(i=0;i<3;i++)
{
determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] – a[1][(i+2)%3]*a[2][(i+1)%3]));
printf(“\nInverse of matrix is: \n\n”);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“%.2f\t”,((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) – (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/ determinant);
printf(“\n”);
}
}
getch();
}
[/message_box]
[/nextpage]
[nextpage title=”OUTPUT” ]
[message_box title=”OUTPUT” color=”yellow”]
Enter the 9 elements of matrix: 3
5
2
1
5
8
3
9
2
The matrix is
3Â Â Â Â Â Â 5Â Â Â Â Â Â 2
1Â Â Â Â Â Â 5Â Â Â Â Â Â 8
3Â Â Â Â Â Â 9Â Â Â Â Â Â 2
Inverse of matrix is:
0.70Â Â Â -0.25Â Â 0.07
-0.09Â Â -0.00Â Â 0.14
-0.34Â Â 0.25Â Â Â -0.11
[/message_box]
[/nextpage]