0% found this document useful (0 votes)
4 views1 page

C Program to Calculate Determinant

The document contains C code to calculate the determinant of a 3x3 matrix. It defines a main function and a determinant function. The main function takes user input for the matrix, calls the determinant function, and prints the result. The determinant function calculates the determinant by multiplying terms according to their positions in the matrix and subtracting or adding them.

Uploaded by

B1ble45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

C Program to Calculate Determinant

The document contains C code to calculate the determinant of a 3x3 matrix. It defines a main function and a determinant function. The main function takes user input for the matrix, calls the determinant function, and prints the result. The determinant function calculates the determinant by multiplying terms according to their positions in the matrix and subtracting or adding them.

Uploaded by

B1ble45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
int determinant(int a[][20]);
int main()
{ int a[20][20],i,j,D;
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
scanf("%i",&a[i][j]);
}
D=determinant(a);
printf("%i",D);
}
int determinant(int a[][20])
{ int i,j,P1=1,P2=1,det,p1=0,p2=0,p3=0,p4=0,k,l,m,n;
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
if(i==j)
P1*=a[i][j];
if(i+j==4)
P2*=a[i][j];
}
}
for(i=1;i<4;i++)
{
for(j=1;j<4;j++)
{
if(i==j+1)
p1*=a[i][j];
if(j==i+1)
p2*=a[i][j];
}
}
for(k=2;k<4;k++)
{
for(l=3;l>1;l--)
{
if(k!=l)
p3*=a[k][l];
}
}
for(m=1;m<3;m++)
{
for(n=2;n>0;n--)
{
if(m!=n)
p4*=a[m][n];
}
}
det=P1-P2+p1*a[1][3]+p2*a[3][1]-p3*a[1][1]-p4*a[3][3];
return det;
}

You might also like