Mathematics Operation With Delphi

13 05 2009

Operasi matematik dengan delphi, bisa ngga ya?? ok, langsung aja ke contoh-contoh programnya:

Tangen:

procedure TForm1.Button1Click(Sender: TObject);
var
  float : single;
begin
  float := Tan(PI/4);
  ShowMessage('Tan(PI/4) = '+FloatToStr(float));
end;

Ket: Ketika program dijalankan dan button1 ditekan, maka akan muncul message yang berupa nilai Tan(PI/4) atau nilai Tan(180/4), dimana PI=180 (Untuk mencari nilai sin maupun cos dapat digunakan dengan cara yang sama)

ArcCos :

var
  float : single;
begin
  float := ArcCos(0.5);
  float := RadToDeg(float);
  ShowMessage('ArcCos of 0.5 = '+FloatToStr(float)+' degrees');
end;

Sqrt :

var
  number, squareRoot : Extended;

begin
 // contoh prog : akar pangkat 2 dari 4
  number  := 4;
  squareRoot := Sqrt(number);
  ShowMessageFmt('Square root of %f = %f',[number, squareRoot]);

end;

Nb: Oiya, jangan lupa untuk menambahkan “math” pada uses

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

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: