Показать сообщение отдельно
  #12  
Старый 18.05.2012, 00:21
Аватар для angvelem
angvelem angvelem вне форума
.
 
Регистрация: 18.05.2011
Адрес: Омск
Сообщения: 3,970
Версия Delphi: 3,5,7,10,12,XE2
Репутация: выкл
По умолчанию

Что считает непонятно:
Код:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Spin, Grids, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Button4: TButton;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1 : TForm1;
  kol   : Integer;

implementation

uses
  Unit1;

var
  obr : Tvek;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I, J : Integer;
begin
  Button2.Enabled := True;
  Randomize;
  for I := 0 to kol - 1 do
    for J := 0 to kol - 1 do
      StringGrid1.Cells[I, J] := IntToStr(random(100) - 50);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  kol := 1;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  I, J : Integer;
begin
  for I := 0 to kol - 1 do
    for J := 0 to kol - 1 do
      obr[I, J] := StrToFloat(StringGrid1.Cells[J, I]);
  Obratis(obr, kol);

  for I := 0 to kol - 1 do
    for J := 0 to kol - 1 do
      StringGrid2.Cells[I, J] := FloatToStr(Round(obr[J, I]));
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  kol := StrToInt(edit1.text);
  StringGrid1.ColCount := kol;
  StringGrid1.RowCount := kol;
  StringGrid2.ColCount := kol;
  StringGrid2.RowCount := kol;
end;

end.

Код:
unit unit1;

interface

type
  Tvek = array[0..30, 0..30] of Single;

procedure Obratis(var obr : Tvek; kol : Integer);

implementation

procedure Obratis(var obr : Tvek; kol : Integer);
var
  I, J, K : Integer;
  buf     : array[0..30, 0..30] of Single;
begin
  for K := 0 to kol - 1 do
  begin
    for I := 0 to kol - 1 do
      for J := 0 to kol - 1 do
      begin
        if (I = K) and (J = K) then
          buf[I, J] := 1 / obr[I, J];

        if (I = K) and (J <> K) then
          buf[I, J] := -obr[I, J] / obr[K, K];

        if (I <> K) and (J = K) then
          buf[I, J] := obr[I, K] / obr[K, K];

        if (I <> K) and (J <> K) then
          buf[I, J] := obr[I, J] - obr[K, J] * obr[I, K] / obr[K, K];
      end;

    for I := 0 to kol - 1 do
      for J := 0 to kol - 1 do
        obr[I, J] := buf[I, J];
  end;
end;

end.
__________________
Je venus de nulle part
55.026263 с.ш., 73.397636 в.д.
Ответить с цитированием