#include<iostream>
#include<iomanip>
using namespace std;
int main() {
int n;
cout << "Enter the order of square matrix: ";
cin >> n;
double A[10][11]; // augmented matrix [A|B]
// Input augmented matrix
cout << "Enter the elements of augmented matrix row-wise:\n";
for(int i=0; i<n; i++) {
for(int j=0; j<=n; j++) {
cin >> A[i][j];
}
}
// Gauss-Jordan elimination
for(int i=0; i<n; i++) {
// Make the diagonal element 1
double diag = A[i][i];
for(int j=0; j<=n; j++) {
A[i][j] = A[i][j] / diag;
}
// Make other elements in current column 0
for(int k=0; k<n; k++) {
if(k != i) {
double factor = A[k][i];
for(int j=0; j<=n; j++) {
A[k][j] = A[k][j] - factor * A[i][j];
}
}
}
}
// Display Final Row-Echelon Form
cout << fixed << setprecision(4);
cout << "\nFinal Row-Echelon Form [A|B]:\n";
for(int i=0; i<n; i++) {
for(int j=0; j<=n; j++) {
cout << A[i][j] << " ";
}
cout << endl;
}
// Display solution
cout << "\nThe solution is:\n";
for(int i=0; i<n; i++) {
cout << "x" << i+1 << " = " << A[i][n] << endl;
}
return 0;
}