// Program: Zhang jianbo
# Include "iostream. H"
Double N [3] [4] = {
{0.0001, 0.5402, 0.3425, 0.8828 },
{1.235, 2.567, 0.9750, 4.777 },
{1.024, 2.001, 4.555, 7.580 }};
Void print ()
{
// Output matrix
Cout <"/n ----------------------------------/N ";
For (INT I = 0; I <3; I ++)
{
For (int K = 0; k <4; k ++)
{Cout <n [I] [k] <"";
If (N [I] [k] = 0) cout <"";
}
Cout <"/N ";
}
Cout <"/n ----------------------------------/N ";
}
Void F1 ()
{// Adjust the matrix in ascending order
Double TMP;
Int K = 0;
Int p = 0, q = 0;
// Bubble Method
For (INT I = P; I <3; I ++)
For (Int J = P; j <3; j ++)
{
If (N [I] [Q] = N [J] [Q] & N [I] [Q] = 0)
{
// If the value of 1st elements in each row is 0, the values are sorted by 2nd elements.
// And so on. If the value of element 2nd is 0, the elements are sorted by 3rd.
Q ++;
}
Else
If (N [I] [Q]> N [J] [Q])
{// Sort rows by key elements
For (k = 0; k <4; k ++)
{
TMP = N [I] [k];
N [I] [k] = N [J] [k];
N [J] [k] = TMP;
}
}
}
}
Void F2 ()
{
// Cancel the RMB
// Change the coefficient of 1st to 1.
Int I;
Double A, T [4];
// By default, the elimination starts from line 1 and starts from line 1.
Int r = 1, L = 0; // R = row L = Column
Int q = 0;
Int h = 0;
Int n = 1;
Loop:
For (H = r; H <3; H ++)
{
A =-N [H] [Q]/n [Q] [Q];
For (I = Q; I <4; I ++)
{
T [I] = N [Q] [I] *;
N [H] [I] + = T [I];
}
Cout <"/n no." <n ++ <"sub-offset/N"; print ();
If (h> 0 & H <3 & N [h-1] [Q] = 0 & N [h-1] [Q] = N [H] [Q])
{
F1 (); // sort
Q ++;
R ++;
Print ();
Goto loop;
}
}
}
Void F3 ()
{
// Iteration Root
Int n = 0;
Double X2 = (N [2] [3]-N [2] [1]-N [2] [0])/n [2] [2];
Double X1 = (N [1] [3]-N [1] [2] * x2-N [1] [0])/n [1] [1];
Double X0 = (N [0] [3]-N [0] [2] * x2-N [0] [1] * x2)/n [0] [0];
Cout <"X0 =" <x0 <"X1 =" <X1 <"X2 =" <X2 <Endl;
}
Void main ()
{
Cout <"original matrix:/N ";
Print ();
Cout <"sorting:/N ";
F1 (); // sort
Print ();
F2 (); // consumer
Print ();
F3 ();
}