Answered # help matrix

nitinmbhanu -3

1

```
//TO FIND INVERSE OF A MATRIX
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<iomanip.h>
float A[3][3],B[3][3];
int i,j,k,l,m,n,e,f,g,h;
float det=0;
void main()
{
clrscr();
cout<<"Enter the 3x3 matrix :\n";//Enters the matrix
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>A[i][j];
//To find cofactor and determinant
for(i=0,k=1,m=2,e=-1,g=2;i<3;i++,e++,g--,k-=g,m-=e)
{
for(j=0,l=1,n=2,f=-1,h=2;j<3;j++,f++,h--,l-=h,n-=f)
{
B[i][j]=pow(-1,(i+j))*((A[k][l]*A[m][n])-(A[m][l]*A[k][n]));
if(i==0)
{
det+=A[i][j]*B[i][j];
}
}
}
cout<<"The determinant of the matrix is "<<det;
cout<<"\nCofactor of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<B[i][j]<<"\t";
}
//To find adjoint
for(i=0;i<3;i++)
for(j=0;j<3;j++)
A[i][j]=B[j][i];
cout<<"\nAdjoint of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";
}
//To find inverse
for(i=0;i<=2;i++)
{
for(j=0;j<3;j++)
A[i][j]*=(1/det);
}
cout<<"\nInverse of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";
}
}
getch();
}
```

This question has already been answered. Start a new discussion instead.

Recommended Articles

I am currently creating a simulation of a pizza ordering system in object oriented program. I have some question. the instruction and guideline is long but I will try and cut it down a lot. the instruction is to create a program that simulate a pizza restaurant using ...

```
#include <stdio.h>
int main(void)
int movieChoice;
int seatNum;
int seatPlan[5][10] = { 0 };
int rows, cols;
char space;
void seatDisplay(int a[][10]);
void seatNew(int n[][10]);
void seatDisplay(int a[][10]) { //this function shows the seat plan
for (int i = 0; i<5; i++) {
for (int j = 0; j<10; j++) ...
```

I have this tree format.

```
> myapp->
> setup.py
> tests ->
> test_myapp.py
> myapp ->
> __init__.py
> myapp.py
```

And from test_myapp.py, I am calling: `from myapp import myapp`

and when I run`python setup.py test`

I am getting `No module named 'myapp'`