Int Void Int Void Int Int Double
Int Void Int Void Int Int Double
Int Void Int Void Int Int Double
// Name: MATRIXDETERMINANT
// Inputs:determinant elements
// Returns:determinant
#include "iostream.h"
#include "conio.h"
int calc(int [],int dim);
void revmatrix( int [],int dim);
void main()
{
int matrix[1000] = {NULL};
int dim,temp;
double leftsum,rightsum;
cout<<"\n\n\n"<<"
PLEASE ENTER MATRIX DIMANTION : ";
cin>>dim;
cout<<"\n\n\n";
for( int i = 0;i<( dim*dim );i ++ )
{
cout<<"ENTER ELEMAN : ";
cin>>temp;
matrix[i] = temp;
cout<<"\n";
clrscr();
cout<<"PLEASE ENTER MATRIX DIMANTION : "<<dim;
cout<<"\n\n\n";
}//for i
if ( dim > 2 )
{
leftsum = calc( matrix , dim );
cout<<"LEFTSUM of the matrix = "<< leftsum <<"\n\n";
revmatrix( matrix , dim );
rightsum = calc( matrix ,dim );
cout<<"RIGHTSUM of the matrix = "<< rightsum <<"\n\n\n\n\n\n" ;
cout<<"
( DETERMINAN OF THE MATRIX = "<< leftsum - rightsum<<" )";
}
else
{
cout<<"
( DETERMINAN OF THE MATRIX = "<<(matrix[0] * matrix[3] matrix[1] *
matrix[2])<<" )";
}
getch();
}//end main
/////////////////calc function//////////
//////////////
int calc( int matrix[], int dim )
{
int sum = 0, bul, x = 1;
for( int l = 0; l<( dim*dim );l += ( dim+1 ) )//ghotr asli
x *= matrix[l];
sum = x;
x = 1;
for( int c = 1;c<dim;c ++ )
{
bul=c;
for( int m = 0;m<dim;m ++ )
{
if( ( bul+1 )%dim != 0 )
{
x *= matrix[bul];
bul +=( dim + 1 );
}
else
{
x = x * matrix[bul];
bul += 1;
}
}//for m
sum += x;
x = 1;
}//for c
return sum;}
////////////////////revmatriv determinan
///////////////////
void revmatrix(int matrix[],int dim)
{
int end,temp,counter;
for( int t = dim-1;t <= dim*dim;t = t + dim )
{
end=t;
counter = end -( dim-1 );
while( end > counter )
{
temp = matrix[end];
matrix[end] = matrix[counter];
matrix[counter] = temp;
++ counter;
-- end;
}
}
}