# C Program to Find the Inverse of 2×2 Matrix

## Introduction

In this post, I am going to write a c program to find the inverse of the 2×2 matrix. For this, we will use a two-dimensional array.

This program will work only for the 2×2 matrix. For writing this program, we must know to find the inverse of the matrix. Basically, this is the topic of mathematics. Before writing this program, let me tell you the steps for finding the inverse.

1. Read the 2×2 matrix from the user.
2. Calculate the determinant of this matrix. If the determinant is 0 then terminate the program and read another matrix. We are going to divide the adjoint of matrix with this value of determinant. We know that we can divide anything by 0.
3. Now, find the adjoint of the matrix.
4. Here we will get our final output. Divide the adjoint of matrix by determinant of the same matrix and this is the output.
5. Stop

Don’t worry I am going to explain the above steps and after that, you can see the actual c program. Let’s see the above steps in detail.

### 1. Read the 2×2 matrix from the user.

Suppose that matrix is and we are calling it as matrix A.

### 2. Calculate the determinant of this matrix.

In this step, we are going to find the determinant of the matrix i.e. | A |.

As you can see from the above figure, the determinant of the matrix is not equal to 0. Now, we can go to the next step.

### 3. Find the adjoint of the matrix.

In the given matrix A, for finding the adjoint of the matrix, interchange the position of 1 and 4 and change the sign of 2 and 3. So the adjoint of the matrix will look like

### 4. Divide the adjoint of matrix by the determinant

Formula Used: A-1=Adjoint of A / Determinant of A

Here, A-1 is nothing but the inverse of matrix A.

I hope you have understood all the steps. Now, you can easily write a c program to find the inverse of the 2×2 matrix.

But if you have any problems, then see the following program.

## C Program to Find the Inverse of 2×2 Matrix

```#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j;
float invA;
printf("Enter elements for 2 * 2 matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&A[i][j]);
}
}
/* Calculate determinant of matrix A */
d = (A*A)-(A*A);
if(d==0)
{
printf("Determinant cannot be ZERO");
return 0;
}
/* Find adjoint of matrix A */
printf("Matrix A is\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",A[i][j]);
}
printf("\n");
}
/* Find Inverse of A */
printf("Inverse of Matrix A is\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%.1f ",invA[i][j]);
}
printf("\n");
}
return 0;
}
```

### Output 2

I hope, you have understood this program. If you have any difficulty understanding this program, then contact me. I will definitely help you.

Thank you.