ює 0.
Лістинг програми
# include "Unit1. h "
// --------------------------------------------- ------------------------------
# pragma package (smart_init)
# pragma resource "*. dfm "
TForm1 * Form1;
int n = 0, l = 0;
float r = 0, p = 0;
const x = 100;
float A [x] [x], Ver [x] [x], Nig [x] [x];
float * X;
float * Y;
bool fl1 = false;
// --------------------------------------------- ------------------------------
__fastcall TForm1 :: TForm1 (TComponent * Owner)
: TForm (Owner)
{
}
// --------------------------------------------- ------------------------------
void __ fastcall TForm1 :: ButtonOkClick (TObject * Sender)
{
TryStrToInt (Edit1-> Text, n);
if (n> 1)
{
StringGrid1-> Enabled = true;
StringGrid1-> RowCount = n;
StringGrid1-> ColCount = n +1;
ButtonClear-> Enabled = true;
ButtonOk-> Enabled = false;
StringGrid1-> Color = clWindow;
ButtonGauss-> Enabled = true;
ButtonHolec-> Enabled = true;
X = new float [n];
for (int i = 0; i
{
for (int j = 0; j
{
A [i] [j] = NULL;
}
X [i] = NULL;
}
}
else
{
ShowMessage ("Число має бути дійсного типу!");
}
}
// --------------------------------------------- ------------------------------
void __ fastcall TForm1 :: ButtonClearClick (TObject * Sender)
{
StringGrid1-> Enabled = false;
StringGrid1-> RowCount = 0;
StringGrid1-> ColCount = 0;
ButtonClear-> Enabled = false;
ButtonOk-> Enabled = true;
StringGrid1-> Color = clBtnFace;
ButtonGauss-> Enabled = false;
}
// --------------------------------------------- ------------------------------
void __ fastcall TForm1 :: ButtonGaussClick (TObject * Sender)
{
Memo1-> Lines-> Clear ();
for (int i = 0; i
{
for (int j = 0; j
{
TryStrToFloat (StringGrid1-> Cells [j] [i], A [I] [j]);
}
}
for (int i = 0; i
{
for (int j = 0; j
{
if (A [i] [j] == NULL)
{
ShowMessage ("Помилка! Є порожні клітинки!");
fl1 = true;
i = n;
break;
}
}
}
Memo1-> Lines-> Add ("МЕТОД Гаусс: ");
Memo1-> Lines-> Add ("");
if (! fl1) {
Memo1-> Lines-> Add ("Матриця приводиться до ступенчатому увазі: ");
l = 0;
for (int i = 0; i
{
for (int j = n-1; j> i; j -)
{
if (A [j-1] [l]
{
for (int k = 0; k
{
r = A [j] [k];
A [j] [k] = A [j-1] [k];
A [j-1] [k] = r;
}
l = 0;
}
else
{
if (A [j-1] [l] == A [j] [l])
{
l + +;
j + +;
}
if (l == n +1)
{
j -;
l = 0;
}
}
}
}
for (int k = 0; k
{
for (int i = k; i
{
r = A [i] [k];
for (int j = k; j
{
A [i] [j] = A [i] [j]/r;
}
}
for (int i = k +1; i
{
for (int j = k; j
{
A [i] [j] = A [i] [j]-A [k] [j];
}
}
}
X [n-1] = A [n-1] [n]/A [n-1] [n-1];
for (int i = n-2; i> = 0; i -)
{
r = A [i] [n];
for (int j = i +1; j <= n-1; j + +)
r = r-A [i] [j] * X [j];
X [i] = r/A [i] [i];
}
String s = "";
for (int i = 0; i
{
s = "";
for (int j = 0; j
{
s + = FloatToStr (A [i] [j]) + "";
}
Memo1-> Lines-> Add (s);
}
Memo1-> Lines-> Add ("");
Memo1-> Lines-> Add ("Коріння СЛАР рівні: ");
for (int i = 0; i
{
if (X [i]! = NULL)
{
Memo1-> Lines-> Add ("x" + IntToStr (I +1) + "=" + FloatToStr (X [i]));
}
else
{
Memo1-> Lines-> Add ("Немає коренів!");
break;
}
}
}
}
// --------------------------------------------- ------------------------------
void __ fastcall TForm1 :: ButtonExitClick (TObject * Sender)
{
Close ();
}
// --------------------------------------------- ------------------------------
void __ fastcall TForm1 :: RadioButton2Click (TObject * Sender)
...