Skip to content

Instantly share code, notes, and snippets.

@kuzemkon
Created November 29, 2014 20:12
Show Gist options
  • Select an option

  • Save kuzemkon/9e0e5cc5d691e4cd1ac3 to your computer and use it in GitHub Desktop.

Select an option

Save kuzemkon/9e0e5cc5d691e4cd1ac3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
using namespace std;
double mat[10][10];
double vec[10];
double e[10];
int n;
double x, a, b;
int main() {
cout << "Enter number of unknown" << endl;
cout << "n=";
cin >> n;
for (int i=1; i<=n; i++) {
b= vec[i];
for (int j=1; j<=n; j++) {
a = mat[i][j];
cout << "Enter coeficients of system left side" << endl;
cout << "a[" << i << "," << j << "]=";
cin >> a;
}
cout << "Enter coeficients of system right side" << endl;
cout << "a[" << i << "," << n+1 << "]=";
cin >> b;
}
if (n == 1) {
x = b/a;
cout << "x=" << x;
}
else if (mat[1][1] != 1) {
for (int j=1; j<=n; j++) {
mat[1][j] = mat[1][j]/mat[1][1];
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++) {
while (i>j) {
mat[i][j] =mat[i][j] - mat[1][j]*mat[i][1];
}
}
}
e[n] = vec[n]/mat[n][n];
for (int i=n; i>0; i=i-1) {
for (int j = n; j >0; j=j-1) {
mat[n-i][j] =mat[n-i][j]*e[i];
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment