// Written by Hosung Leo Kim #include using namespace std; void dumpCoeff( float coeff[10][11], int N ) { for ( int i = 0; i < N; i++ ) { for ( int j = 0; j < ( N + 1 ); j++ ) { cout.setf( ios::fixed ); cout.setf( ios::showpoint ); cout.precision( 2 ); cout.width(8); cout << coeff[i][j] ; } cout << endl; } } // dumpCoeff() int main() { float coeff[10][11]; int N = 3; coeff[0][0] = 2; coeff[0][1] = 3; coeff[0][2] = 1; coeff[0][3] = 11; coeff[1][0] = 4; coeff[1][1] = -2; coeff[1][2] = 3; coeff[1][3] = 9; coeff[2][0] = 3; coeff[2][1] = 5; coeff[2][2] = -3; coeff[2][3] = 4; dumpCoeff( coeff, N ); for ( int i = 0; i < N; i++ ) // for each column { cout << endl << "column " << i << ":" << endl; float divisor = coeff[i][i]; for ( int k = 0; k < ( N + 1 ); k++ ) coeff[i][k] /= divisor; dumpCoeff( coeff, N ); for ( int j = 0; j < N; j++ ) // for each row { if ( j != i ) { float multiplier = coeff[j][i]; for ( int k = 0; k < ( N + 1 ); k++ ) coeff[j][k] -= coeff[i][k] * multiplier; cout << endl; dumpCoeff( coeff, N ); } } // for j } // for i return 0; } /* /homes/home30/hkim16/107/lab10> a.out 2.00 3.00 1.00 11.00 4.00 -2.00 3.00 9.00 3.00 5.00 -3.00 4.00 column 0: 1.00 1.50 0.50 5.50 4.00 -2.00 3.00 9.00 3.00 5.00 -3.00 4.00 1.00 1.50 0.50 5.50 0.00 -8.00 1.00 -13.00 3.00 5.00 -3.00 4.00 1.00 1.50 0.50 5.50 0.00 -8.00 1.00 -13.00 0.00 0.50 -4.50 -12.50 column 1: 1.00 1.50 0.50 5.50 -0.00 1.00 -0.12 1.62 0.00 0.50 -4.50 -12.50 1.00 0.00 0.69 3.06 -0.00 1.00 -0.12 1.62 0.00 0.50 -4.50 -12.50 1.00 0.00 0.69 3.06 -0.00 1.00 -0.12 1.62 0.00 0.00 -4.44 -13.31 column 2: 1.00 0.00 0.69 3.06 -0.00 1.00 -0.12 1.62 -0.00 -0.00 1.00 3.00 1.00 0.00 0.00 1.00 -0.00 1.00 -0.12 1.62 -0.00 -0.00 1.00 3.00 1.00 0.00 0.00 1.00 -0.00 1.00 0.00 2.00 -0.00 -0.00 1.00 3.00 /homes/home30/hkim16/107/lab10> */