0% found this document useful (0 votes)
39 views2 pages

Int Void Int Void Int Int Double

This document contains code for calculating the determinant of a matrix. It defines functions to calculate the determinant of a given matrix, and to reverse the order of elements in a matrix. The main function gets user input to define a matrix, calls the calculation function on the original and reversed matrix, and outputs the determinant as the difference between the two results. The calculation function multiplies corresponding elements along the main diagonal and calculates a running sum of signed diagonal products to derive the determinant.

Uploaded by

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

Int Void Int Void Int Int Double

This document contains code for calculating the determinant of a matrix. It defines functions to calculate the determinant of a given matrix, and to reverse the order of elements in a matrix. The main function gets user input to define a matrix, calls the calculation function on the original and reversed matrix, and outputs the determinant as the difference between the two results. The calculation function multiplies corresponding elements along the main diagonal and calculates a running sum of signed diagonal products to derive the determinant.

Uploaded by

Irzam Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

//**************************************

// 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;
}
}
}

You might also like