/* DETERMINANT OF A MATRIX */
#include<stdio.h>
#include<conio.h>
void main()
{
float a[10][10],mul,det=1.0,b;
int i,j,k,n;
clrscr();
printf("\n\t\tINPUT:");
printf("\n\t\t------");
printf("\n\t\tEnter the value for n: ");
scanf("%d",&n);
printf("\n\t\tEnter the matrix\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("\t\t%f",&b);
a[i][j]=b;
}
printf("\n\t\t");
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j) continue;
mul=a[j][i]/a[i][i];
for(k=1;k<=n;k++)
{
a[j][k]=a[j][k]-mul*a[i][k];
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
det=det*a[i][i];
}
}
printf("\n\t\tOUTPUT:");
printf("\n\t\t-------");
if(det==0)
{
printf("\n\t\tThe given matrix is Singular Matrix");
exit(0);
}
else
{
printf("\n\t\tDeterminant of matrix is: %f",det);
}
getch();
}
INPUT:
------
Enter the value for n: 2
Enter the matrix:
2 3
4 5
OUTPUT:
-------
Determinant of matrix is: -2.000000
No comments:
Post a Comment