Está en la página 1de 2

//CREADOR:BRYAN BRITTUS(SNYDER)

//PROGRAMA PARA HALLAR LA DETERMINANTE DE ORDEN "n" EN C++


(CI PLUS PLUS)
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
int DETERMINANTE(int a[][100],int orden);//prototipo de la funcion
det
main()
{
int n;
int mat[100][100];
srand(time(NULL));
cout<<"Ingrese el orden de la matriz:";cin>>n;

for(int j=0;j<n;j++)
for(int i=0;i<n;i++)
mat[i][j]=rand()%11;
cout<<"La matriz aleatoria es:"<<endl;
for(int j=0;j<n;j++)
{for(int i=0;i<n;i++)
cout<<mat[i][j]<<" ";
cout<<endl;
}
cout<<"Su determinante es: "<<DETERMINANTE(mat,n)<<endl;
system("pause");
}
int DETERMINANTE(int a[][100],int orden)
{
int det=0;
int aux1[100][100];
int aux2[100][100];

if(orden==1)
return a[0][0];
for(int i=0;i<orden;i++)
{
if(i%2==0)

{for(int y=0;y<orden;y++)
for(int x=0;x<orden;x++)
if(x<i)
aux1[x][y]=a[x][y+1];
else
aux1[x][y]=a[x+1][y+1];
det=det+a[i][0]*DETERMINANTE(aux1,orden-1);
}
else
{for(int y=0;y<orden;y++)
for(int x=0;x<orden;x++)
if(x<i)
aux2[x][y]=a[x][y+1];
else
aux2[x][y]=a[x+1][y+1];
det=det-a[i][0]*DETERMINANTE(aux2,orden-1);
}
}
return det;
}
/*Para mayor eficiencia los invito a pasen este programa a orientado a
obejtos
y creen un funcion para la matriz!!!*/

También podría gustarte