This is gonna be the shortest and most efficient way to find determinant of N x N order my OWN new LOGIC.
Coding :
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
float arr[10][10];
float div[10],sub[10];
int n;
cout << "Entr Order of matrix :- ";
cin >> n;
cout << endl;
for(int i=0;i<n;i++)
{
if(i==0)
cout << (i+1) << "st Row of MATRIX: \n";
else if(i==1)
cout << (i+1) << "nd Row of MATRIX: \n";
else if(i==2)
cout << (i+1) << "rd Row of MATRIX: \n";
else
cout << (i+1) << "th Row of MATRIX: \n";
for(int j=0;j<n;j++)
cin >> arr[i][j];
cout << endl;
}
cout << endl << endl << "--------YOUR ENTERED MATRIX--------- " << endl;
for(int i=0;i<n;i++)
{
cout << endl;
for(int j=0;j<n;j++)
{
cout << arr[i][j] << " ";
}
}
for(int k=0;k<(n);k++)
{
for(int i=k;i<n;i++)
{
for(int j=k;j<n;j++)
{
div[j] = arr[k+0][j] / arr[k+0][k+0];
sub[j] = div[j]*arr[i+1][k+0];
}
for(int j=0;j<n;j++)
{
arr[i+1][j]-=sub[j];
}
}
}
float ans=1;
for(int i=0;i<n;i++)
{
ans*=arr[i][i];
}
cout << endl << endl << "-------Determinant of Matrix = " << ans;
}
No comments:
Post a Comment