unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, Grids, StdCtrls, math;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
Label3: TLabel;
Edit3: TEdit;
procedure Edit2Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//startdarstellung
stringgrid1.Cells[0,0]:='
Schritt';
stringgrid1.cells[1,0]:='
Näherungswert';
edit3.text:=floattostr(sqrt(strtoint(edit1.text)));
//edit1 ereignis simulieren
edit1.OnChange(
nil);
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
wurzel,r:double;
st,i:integer;
begin
try
//stringgrid leeren
stringgrid1.RowCount:=2;
stringgrid1.Cells[0,1]:='
';
stringgrid1.Cells[1,1]:='
';
//predeklination
i:=0;
wurzel:=1;
st:=strtoint(edit2.text);
//if st>10 then st:=10;
r:=strtofloat(edit1.text);
//ausgabe
edit3.text:=floattostr(sqrt(r));
//heron
repeat
i:=i+1;
wurzel:=0.5*(wurzel+r/wurzel);
stringgrid1.RowCount:=i+1;
stringgrid1.cells[0,i]:=inttostr(i);
stringgrid1.Cells[1,i]:=floattostr(wurzel);
until copy(floattostr(wurzel),1,pos('
,',floattostr(wurzel))+st) = copy(edit3.text,1,pos('
,',edit3.text)+st)
except beep
end;
//stringgrid ausrichten
if i>7
then stringgrid1.TopRow:=i-6;
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
//edit1 ereignis simulieren
edit1.OnChange(
nil);
end;
end.