Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
Never
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Math;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function fact(j: Integer): Integer;
var
i,f: Integer;

begin
for i := 0 to j do
begin
  if (i=0) or (i=1) then
    f:=1
      else
       f:=f*i;
       end;
  fact:=f;
end;



procedure TForm1.Button2Click(Sender: TObject);
begin
close
end;

procedure TForm1.Button1Click(Sender: TObject);
var ans,x,eps:extended;
var k:integer;
begin
x:=strtofloat (edit1.Text);
eps:=strtofloat(edit2.Text);
k:=0;
ans:=0;
if eps>0 then
  begin
  while (ans>eps) do
    begin
      ans:=(power(-1,k))*power((4*k+3),x)/(fact(2*k+1)*(4*k+3));
      k:=k+1;
    end;
  edit3.Text:=floattostr(ans);
  end
else
edit3.Text:='Eps <= 0';
end;

end.