Skip to content

Instantly share code, notes, and snippets.

@kuzemkon
Created December 9, 2014 12:25
Show Gist options
  • Select an option

  • Save kuzemkon/2d78a7b758910af109f4 to your computer and use it in GitHub Desktop.

Select an option

Save kuzemkon/2d78a7b758910af109f4 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
int main() {
double a[3][3];
double b[3];
for (int i=1; i<4; i++) {
for (int j=1; j<4; j++) {
cout << "Enter left side coeficients" << endl;
cout << "a[" << i << "," << j << "]=";
cin >> a[i][j];
}
cout << "Enter right side coeficients" << endl;
cout << "b[" << i << ",4]=";
cin >> b[i];
}
double det, detx, dety, detz;
det = a[1][1]*(a[2][2]*a[3][3]-a[3][2]*a[2][3])+a[1][2]*(a[2][1]*a[3][3]-a[3][1]*a[2][3])+a[1][3]*(a[2][1]*a[3][2]-a[3][1]*a[2][2]);
detx = b[1]*(a[2][2]*a[3][3]-a[3][2]*a[2][3])+a[1][2]*(b[2]*a[3][3]-b[3]*a[2][3])+a[1][3]*(b[2]*a[3][2]-b[3]*a[2][2]);
dety = a[1][1]*(b[2]*a[3][3]-b[3]*a[2][3])+b[1]*(a[2][1]*a[3][3]-a[3][1]*a[2][3])+a[1][3]*(a[2][1]*b[3]-a[3][1]*b[2]);
detz = a[1][1]*(a[2][2]*b[3]-a[3][2]*b[2])+a[1][2]*(a[2][1]*b[3]-a[3][1]*b[2])+b[1]*(a[2][1]*a[3][2]-a[3][1]*a[2][2]);
if (det==0 && detx==0 && dety==0 && detz==0) {
cout << "The system have infinity nubers of equation";
}
else if (det==0) {
cout << "The system have no equations";
}
else {
double x[3];
x[1] = det/detx;
x[2] = det/dety;
x[3] = det/detz;
for (int i=1; i<4; i++) {
cout << "x[" << i << "]=" << x[i] << endl;
}
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment