C program to calculate the determinant of 3*3 matrix
How to find the determinant of the 3*3 matrix
We use two dimension array to solve the C program to calculate the determinant of the 3*3 matrix.
Since the initial value of the array started from 0 so elements of the matrix are stored as below.
C Program to calculate determinant of 3*3 matrix
|
#include<stdio.h> #include<conio.h> int main() { int a[3][3], i, j, e, f, d, g, h, l, k; // taking input of elements of 3*3 matrix printf("\n Enter 3*3 matrix"); for(i=0;i<3;i++)// outer loop for taking elements of row { for(j=0;j<3;j++)// inner loop for taking elements of column { scanf("%d", &a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { e = a[1][1]*a[2][2] - a[1][2]*a[2][1];// finding a[1][1]*a[2][2] -
a[1][2]*a[2][1] f=a[0][0]*e; // finding
a[0][0]*(a[1][1]*a[2][2] - a[1][2]*a[2][1]) g= a[1][0]*a[2][2] - a[1][2]*a[2][0]; //
a[1][0]*a[2][2] - a[1][2]*a[2][0] h = a[0][1]*g;// finding a[0][1]*(a[1][0]*a[2][2] - a[1][2]*a[2][0] ) k=a[1][0]*a[2][2] - a[1][2]*a[2][0];//a[1][0]*a[2][2] -
a[1][2]*a[2][0] l=a[0][2]*k;// finding a[0][2]( a[1][0]*a[2][2] - a[1][2]*a[2][0]) d=f-h+l; } } // printing determinant of 3*3 matrix printf("\n Determinant of 3*3 matrix
is %d", d); getch(); }
|
Output
In this above example
|
5 is stored in a[0][0] |
3 is stored in a[0][1] |
7 is stored in a[0][2] |
|
8 is stored in a[1][0] |
4 is stored in a[1][1] |
2 is stored in a[1][2] |
|
1 is stored in a[2][0] |
6 is stored in a[2][1] |
1 is stored in a[2][2] |


0 Comments
Please do not enter any spam link on comment box