**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.

**Also Read: **Switch Case in C Program to Calculate Area of Circle and Triangle

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.

- Read the 2×2 matrix from the user.
- 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.
- Now, find the adjoint of the matrix.
- Here we will get our final output. Divide the adjoint of matrix by determinant of the same matrix and this is the output.
- 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.

**Also Read: **C Program to Print Multiples of 5 using do-while loop

**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 A[2][2],d,adjA[2][2]; int i,j; float invA[2][2]; printf("Enter elements for 2 * 2 matrix\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { //Reading Matrix A scanf("%d",&A[i][j]); } } /* Calculate determinant of matrix A */ d = (A[0][0]*A[1][1])-(A[0][1]*A[1][0]); if(d==0) { printf("Determinant cannot be ZERO"); return 0; } /* Find adjoint of matrix A */ adjA[0][0]=A[1][1]; adjA[1][1]=A[0][0]; adjA[0][1]=-A[0][1]; adjA[1][0]=-A[1][0]; 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++) { invA[i][j]=(adjA[i][j])/(float)d; printf("%.1f ",invA[i][j]); } printf("\n"); } return 0; }

**Output 1**

**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.

**Some Important C Programs**

- Program in C to Find Longest Line in a File
- Palindrome in C using Pointers
- Insert and Delete element in Array in C using switch case
- C Program to Add Alternate Elements of a 2D Array
- Arrays in C for Complete Beginners
- C Program to Find Area of a Circle using Preprocessor
- Program in C to Remove White Spaces and Comments from a File
- C Program to Print Numbers Except Multiples of n
- Reverse a Number using getchar and putchar function in c
- The while loop in C Programming