1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include<iostream>
using namespace std;
void ind_val_out(int mat[][3]);
void ind_val_in(int mat[][3]);
int cofactor(int data[][3],int x,int y);
class matrix_3x3
{
public:
void in_value(void)
{
ind_val_in(data);
};
const void out_value(void)
{
ind_val_out(data);
}
const int getdet(void)
{
return det(data);
}
private:
int data[3][3];
int det(int data[][3])
{
int determinant;
int x,y,z;
x=data[0][1]*cofactor(data,0,1);
y=data[0][2]*cofactor(data,0,2);
z=data[0][3]*cofactor(data,0,3);
determinant=x+y+z;
return determinant;
}
};
int main()
{
int x[3][3];
matrix_3x3 A;
A.in_value();
A.out_value();
cout<<A.getdet();
}
void ind_val_out(int mat[][3])
{
int x(0),y(0),z(0);
abc:
cout<<mat[x][y]<<" ";
cout<<mat[x][y+1]<<" ";
cout<<mat[x][y+2]<<"\n";
z++;
if (z<3)
{
x++;
goto abc;
}
}
void ind_val_in(int mat[][3])
{
int x(0),y(0),z(0);
abc:
cin>>mat[x][y];
cin>>mat[x][y+1];
cin>>mat[x][y+2];
z++;
if (z<3)
{
x++;
goto abc;
}
}
int cofactor(int data[][3],int x,int y)
{
int cofactor_v;
cofactor_v = data[(x + 1) % 3][(y + 1) % 3] * data[(x + 2) % 3][(y + 2) % 3] - data[(x + 1) % 3][(y + 2) % 3] * data[(x + 2) % 3][(y + 1) % 3];
return cofactor_v;
}
|