Selasa, 08 November 2011

Fungsi cosinus

 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Ex: TEdit;
    En: TEdit;
    ehasil: TEdit;
    hasil: TButton;
    Derajat: TLabel;
    Sudut: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    keluar: TButton;
    Label5: TLabel;
    procedure hasilClick(Sender: TObject);
    procedure keluarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.hasilClick(Sender: TObject);
var
  x,y,z,a,b,c,tanda:real      ;
  i,j,n      :integer   ;
begin
  y:=1 ;
  x:=strtofloat (Ex.Text);
  n:=strtoInt(En.Text) ;
  for i :=1 to n do
  begin
    if i mod 2=1 then tanda:=-1 else tanda:=1 ;
    a:=1 ;
    b:=1 ;
    for j := 1 to (2*i) do
      begin
        c:=pi/180*x ;
        a:=a*c ;
        b:=b*j ;
      end;
        z:=a/b ;
        y:=y+(tanda*z) ;
  end;
    ehasil.Text:=floattostr(y) ;
end;

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

end.

hasil nya seperti berikut

Tidak ada komentar: