Calculate det ⎝ ⎛ 2 − 3 9 6 1 3 4 5 7 ⎠ ⎞ .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Why is it, 6(5)(9) or can it be any other number that you haven't used?
det ⎝ ⎛ 2 − 3 9 6 1 3 4 5 7 ⎠ ⎞ = ( 2 ) ( 1 ) ( 7 ) + ( 6 ) ( 5 ) ( 9 ) + ( 4 ) ( − 3 ) ( 3 ) − ( 2 ) ( 5 ) ( 3 ) − ( 6 ) ( − 3 ) ( 7 ) − ( 4 ) ( 1 ) ( 9 ) = 1 4 + 2 7 0 − 3 6 − 3 0 + 1 2 6 − 3 6 = 3 0 8
Here is the C program to find determinant of Any matrix, by Me :) Enjoy..
Please Include stdio.h, malloc.h and math.h header files as they are not showing here..
/* C program to find determinant of any matrix, by Vivek Sedani */
//Please Include stdio.h, malloc.h and math.h header files here I dont know why they are not showing here
//also include conio.h If you are using TC
#include"<stdio.h>"
#include <malloc.h>
#include <math.h>
//#include <conio.h> for TC only
#define min(a,b)(a<b?a:b);
int abcd(int a1,int a2,int x)
{
if(a1<a2)
{
if(x>=a1&&x<=a2)
{
return x;
}else return a1;
}
else{
if(x>a2&&x<a1)
{
return a1;
}else return x;
}
}
float determinant(float **a,int row,int col,int s,int os)
{
int i,y,k;
float det=0;
if(1==s){
det=a[row][col];
}
else
{
for(i=0;i<s;i++)
{
y=abcd(col,(col+s-1)%os,(col+i+1)%os);
if((col+s-1)%os-col>0)
k=1; else k=-1;
det=det+a[row][(col+i)%os]*pow(-1,i)*k*determinant(a,(row+1)%os,y,s-1,os);
}
}
return det;
}
void scanmatrix(float **a,int m,int n)
{
int i,j;
for(i=0;i<m;i++)
{
printf("\n Enter %dth row :",i+1);
for(j=0;j<n;j++)
{
scanf("%f",&a[i][j]);
}
}
}
void main()
{
int m,i;
float **a,*ans,det;
// clrscr(); for TC only
printf("\nEnter size of the square matrix :");
scanf("%d",&m);
a=(float **)malloc(sizeof(float *)*m);
for(i=0;i<m;i++)
{
a[i]=(float *)malloc(sizeof(float)*m);
}
scanmatrix(a,m,m);
det=determinant(a,0,0,m,m);
printf("\ndeterminant is %f ",det);
// getch(); for TC only
}
Problem Loading...
Note Loading...
Set Loading...
d e t ∣ ∣ ∣ ∣ ∣ ∣ 2 − 3 9 6 1 3 4 5 7 ∣ ∣ ∣ ∣ ∣ ∣ = [ 2 ( 1 ) ( 7 ) + 6 ( 5 ) ( 9 ) + 4 ( − 3 ) ( 3 ) ] − [ 9 ( 1 ) ( 4 ) + 3 ( 5 ) ( 2 ) + 7 ( − 3 ) ( 6 ) ]
= ( 1 4 + 2 7 0 − 3 6 ) − ( 3 6 + 3 0 − 1 2 6 )
= 2 4 8 − ( − 6 0 )
= 2 4 8 + 6 0
= 3 0 8