write a program to find a inverse of square matrix in c++
Source Code:
/********************************************
program: solution of non-linear equation
bisection method
language: C
Author : Tanveer Khan
Rajasthan University, Jaipur
************************************************/
Source Code:
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
float determinent=0;
clrscr();
cout<<"find inverse of matrix";
cout<<endl<<"enter the element of matrix";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}
}
cout<<"the entered matrix is:\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<"\t"<<a[i][j];
}
for(i=0;i<3;i++)
{
determinent=determinent+(a[0][i]*a[1][(i+1)%3]*a[2][(i+2)%3]-a[1][(i+2)%3]*a[2][(i+1)%3]);
}
if(determinent==0)
{
cout<<endl<<"inverse doesnot exist(determinent=0)\n";
}
else
{
cout<<"\n inverse of matrix is";
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<(a[(i+1)%3][(3+1)%3]*a[(i+2)%3][(j+2)%3]-(a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/determinent;
}
cout<<"\n";
}
getch();
}
OUTPUT:
Comments
Post a Comment