#include <iostream>
using namespace std;
class matrix
{
int a[10][10],b[10][10],c[10][10],x,y,i,j;
public :
void degerler();
void ters();
};
void matrix::degerler()
{
cout << "Satirlari giriniz: "; cin >> x;
cout << "Sütunlari giriniz: "; cin >> y;
cout << "Ilk matris elamanlarini giriniz:\n\n";
for (i=1; i<=x; i++)
{
for (j=1; j<=y; j++)
{
cin >> a[i][j];
}
}
cout << "Ikinci matris elamanlarini giriniz:\n\n";
for (i=1; i<=x; i++)
{
for (j=1; j<=y; j++)
{
cin >> b[i][j];
}
}
}
void matrix::ters()
{
cout << "matrisin tersi\n";
for (i=1; i<=x; i++)
{
for (j=1; j<=y; j++)
{
if(i==j)
{
b[i][j]=1;
}
else
b[i][j]=0;
}
}
float d,k;
for (i=1; i<=x; i++)
{
d=a[i][j];
for (j=1; j<=y; j++)
{
a[i][j]=a[i][j]/d;
b[i][j]=b[i][j]/d;
}
for (int h=0; h<x; h++)
{
if(h!=i)
{
k=a[h][j];
for (j=1; j<=y; j++)
{
a[h][j]=a[h][j]-(a[i][j]*k);
b[h][j]=b[h][j]-(b[i][j]*k);
}
}
count << a[i][j] << "";
}
count << endl;
}
}
int main()
{
int secim;
char ch;
matrix m;
m.degerler();
do
{
cout << "seçiminizi giriniz\n";
cout << " 1. matrisin tersi\n";
cin >> secim;
switch (secim)
{
case 1:
m.ters();
break;
}
cout << "\nBaska bir sey yap/n?";
cin >> ch;
}
while (ch!= 'n');
cout << "\n";
return 0;
}